Here is the piece of code which would escape regular expression, for
what ever characters you really want to escape, i hope i can make code
to escape my girl friend some day too :)
Just type in the charcyerts you want to escape in the upper box, and u
will get a expression on the lower,
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute" width="400" height="200">
<mx:TextArea id="oldstr" text="{}()^$&.*?-/+|[]\"
x="10" y="10" width="380" height="70"/>
<mx:TextArea id="newstr" x="10" y="118" width="380" height="70"/>
<mx:Button x="149" y="88" label="Escape string"
click="handleDoEscape(event)"/>
<mx:Script>
<![CDATA[
// string to test with: {}()^$&.*?-/+|[]\
private function escapeRegexChars(s:String):String
{
var newString:String =
s.replace(
new RegExp("([{}\(\)\^$&.\*\?\/\+\|\[\\\\]|\]|
\-)","g"),
"\\$1");
return newString;
}
private function handleDoEscape(event:Event):void
{
newstr.text = escapeRegexChars(oldstr.text);
}
]]>
</mx:Script>
</mx:Application>
Cheers
Varun Rathore