i had tried escaping them, below i've pasted an example of my problem- 2
samples: 1 looking for [Employee First Name] and one looking for {Employee
First Name}  (curly braces vs square braces) and even though the brackets
are escaped, the regex with [ and ] only return the ending ].  do i have the
regex wrong?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute">
    <mx:Script>
        <![CDATA[
            private var mergeRE:RegExp = new RegExp("\[[^>]*?\]","igm");
            private var mergeRE2:RegExp = new RegExp("{[^>]*?}","igm");

            public function runSquareBracketTest():void
            {
                 var response:Array = subjectString.text.match(mergeRE);
                 resultString.text = response.toString();
            }

            public function runCurlyBracketTest():void
            {
                 var response:Array = subjectString.text.match(mergeRE2);
                 resultString.text = response.toString();
            }
        ]]>
    </mx:Script>

    <mx:VBox>
        <mx:TextArea id="subjectString" width="400" height="200">
            <mx:text>
                <![CDATA[<strong>[Employee First Name] </strong>
<strong>{Employee Last Name} </strong>]]>
            </mx:text>
        </mx:TextArea>
        <mx:TextArea id="resultString" width="400" height="200" />
        <mx:Button click="runSquareBracketTest();" label="Get first name."
/>
        <mx:Button click="runCurlyBracketTest();" label="Get last name." />
    </mx:VBox>
</mx:Application>

On Tue, Apr 15, 2008 at 4:08 PM, Gordon Smith <[EMAIL PROTECTED]> wrote:

>    [ and ] are metacharacters in RegExp patterns. For example, "[abc]"
> matches either "a", or 'b" or "c". To prevent this interpretation, escape
> them with a backslash.
>
>
>
> Gordon Smith
>
> Adobe Flex SDK Team
>
>
>  ------------------------------
>
> *From:* [email protected] [mailto:[EMAIL PROTECTED] *On
> Behalf Of *Derrick Anderson
> *Sent:* Tuesday, April 15, 2008 12:49 PM
> *To:* [email protected]
> *Subject:* [flexcoders] RegExp searching for [ and ], are they reserved?
>
>
>
> hey all,
>
> i'm trying to do a replace on a string and replace anything in brackets
> with something else.
>
> so [this] word would get replaced, however in the regex tester at gskinner
> this works fine (it's flex based regex test tool) but in my local code- i
> always get unexpected results when my regex expression has brackets in it.
>
> private var mergeRE:RegExp = new RegExp("\[[^>]*?]","igm");
>
> is there another escape character i need to use, why does flash have a
> problem searching for [ and ] in regex?
>
> thanks,
> d.
>
>  
>

Reply via email to