I'm trying to use the RegExp class in a search routine, in
which I want to match each word typed by a user to the start of a
word in the text. This means I need a regular expression like
/\bexpr/i for example, to match the word expression - well the
start of it, anyway.
The problem I have is taking the prefix entered by the user
("expr") and making it part of the regexp. Assuming the variable is
userPrefix, I can do something like
var re:RegExp = new RegExp("\\b" + userPrefix, "i");
This works fine as long as the user doesn't type any magic
characters. If the user types "\", for example, I'm left with an
invalid RE. Java has a static method Pattern.quote(), or something
like that, that takes the literal and makes it just a literal from
the point of view of the regexp pattern compiler.
Does anyone know if there's a similar utility for AS3?