i want to check in Adobe AIR if given regex is valid. I'm looking for somtehing similar like here: How to check if a given Regex is valid?
I dont want to compare regex and text-value - i jus want to check if this regex is valid. If someone type invalid regex - for example: "x{5,-3}" or "(((^^$$$)//)" or something like this i just need to communicate to him that this regular expression is not valid - its not proper regular expression.
In Java it can be done by: [code]
try {
Pattern.compile(userInputPattern);
} catch (PatternSyntaxException exception) {
System.err.println(exception.getDescription());
System.exit(1);
}
[/code]
As far as I can tell, you are looking for a test app in which you can enter an regular expression and a value and the app will tell you if there is a match or not. Assuming that is what you want, this code will do it for you:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
private function test(regex:String, value:String):String {
return new RegExp(regex).test(value) ? "MATCH" : "NOT A MATCH";
}
]]>
</fx:Script>
<s:Form>
<s:FormItem label="RegEx:">
<s:TextInput id="regex" />
</s:FormItem>
<s:FormItem label="Test Value: ">
<s:TextInput id="testValue" />
</s:FormItem>
<s:Label text="{test(regex.text, testValue.text)}" />
</s:Form>
</s:WindowedApplication>
If you want to dynamicaly see the result of your regexp on a given input, I suggest you this online tool:
Flex 3 Regular Expression Explorer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With