AIR, Flex - how to verify the regular expression

I want to check in Adobe AIR if a regular expression is specified. I am looking for somtehing similar here: How to check if a given regex is valid?


I do not want to compare regular expression and text value. i jus wants to check if this is a regular expression. If someone typed an invalid regular expression - for example: "x {5, -3}" or "((^^ $$$) //)" or something like this, I just need to tell him that this is regular the expression is not valid - its an incorrect regular expression.

In Java, this can be done: [Code]

try {
            Pattern.compile(userInputPattern);
        } catch (PatternSyntaxException exception) {
            System.err.println(exception.getDescription());
            System.exit(1);
        }

[/the code]

+5
source share
4 answers

, , , , . , , , :

<?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>
+1

""? , , RegExp::test() - ​​ true, , false, .

0

All Articles