tags:

views:

17

answers:

1

For some reason I can't seem to match a parentheses in Flex using Regex to save my life.

What's wrong with this?

var commandTxt:String = "switchview(adf)";
var switchViewArray:Array = commandTxt.match(new RegExp("switchview\(", "i"));

I've tried dozens of things, but I can't seem to get a match the parentheses. What's the catch here?

+3  A: 

I never used Flex, but most likely this is because the \ has a special meaning in double quotes.
Use a double-escape:

new RegExp("switchview\\(", "i");

Or you can also write:

var pattern:RegExp = /switchview\(/i;
... match(pattern)
NullUserException
Yes - apparently you need double escapes when using quotes. So ( needs \\(, \d is \\d, etc. Lame.
jcelgin