i think i figured it out, the [ and ] characters have to be double-escaped like so
new RegExp("\\[[^]*\\]","igm"); d. On Wed, Apr 16, 2008 at 2:17 PM, Derrick Anderson < [EMAIL PROTECTED]> wrote: > just bumping this one up there, it is critical for my app to do this and I > see no way past it. anybody ever needed to find content with regex that > contained [] characters? > > thanks, > d. > > > On Wed, Apr 16, 2008 at 10:01 AM, Derrick Anderson < > [EMAIL PROTECTED]> wrote: > > > hey i'm not a regex pro by far which is why i asked if my regex was > > wrong- but taking your suggestion it still does not work- not sure why. > > i've used the RegExr air app to test this and the simplest i can get it is > > new RegExp("\[[^]*\]","igm"); > > > > this works when {} are used but not when [] is used, you can see in the > > example below- it looks like escaping the [] is affecting the match > > (although it works fine in the regex test tool). > > > > <?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:33 PM, Gordon Smith <[EMAIL PROTECTED]> wrote: > > > > > I'm confused... why isn't your pattern something like "\[.*]\]" ? > > > What's going on with the ^ and the > ? What is supposed to match against > > > letters like E, m, p, l, etc.? > > > > > > > > > > > > Gordon Smith > > > > > > Adobe Flex SDK Team > > > > > > > > > ------------------------------ > > > > > > *From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] > > > *On Behalf Of *Derrick Anderson > > > *Sent:* Tuesday, April 15, 2008 1:23 PM > > > *To:* flexcoders@yahoogroups.com > > > *Subject:* Re: [flexcoders] RegExp searching for [ and ], are they > > > reserved? > > > > > > > > > > > > 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:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] > > > *On Behalf Of *Derrick Anderson > > > *Sent:* Tuesday, April 15, 2008 12:49 PM > > > *To:* flexcoders@yahoogroups.com > > > *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. > > > > > > > > > > > > > > > > > > > >