5

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]

Community
  • 1
  • 1
mihau
  • 247
  • 3
  • 9

4 Answers4

1

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>
Brian Genisio
  • 47,787
  • 16
  • 124
  • 167
  • Not exacly - 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. – mihau Aug 24 '11 at 09:36
  • Gotcha. I don't see anything in the documents that would suggest that RegEx supports this, unfortunately. – Brian Genisio Aug 24 '11 at 12:29
1

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

Davz
  • 1,530
  • 11
  • 24
0

What do you mean by "valid"? If you want to check if the regular expression matches a particular string, you can use RegExp::test() - it will return true if there is a match, false if there isn't.

laurent
  • 88,262
  • 77
  • 290
  • 428
  • I know that - i just want to check if my regex it is not wrong. I need to check that pattern is ok – mihau Aug 23 '11 at 12:09
  • I just want to check if regex syntax is valid - not testing regex on example In Java it can be done by: try { Pattern.compile(userInputPattern); } catch (PatternSyntaxException exception) { System.err.println(exception.getDescription()); System.exit(1); } – mihau Aug 24 '11 at 09:39
  • ok, probrably it cant be done - thats ok - i just wanna know that it can or can not be done – mihau Sep 06 '11 at 07:59
0

I can't find this implemented in AS3, but here there is the source code Pattern.java

https://github.com/unkiwii/Random-Stuff/blob/master/java/src/java/util/regex/Pattern.java

Maybe you can implement the same in AS3.

Lucas Gabriel Sánchez
  • 40,116
  • 20
  • 56
  • 83