Actually, I wrote about this on blogs, so Iβll just point you out: http://tyleregeto.com/using-vars-in-regular-expressions-as3 It talks about possible solutions, but thereβs no ideal one, as you mention .
EDIT
Here is a copy of the important parts of this blog post:
Here is a regular expression to cut tags from a block of text.
/<("[^"]*"|'[^']*'|[^'">])*>/ig
This great expression works like a charm. But I would like to update it so that the developer can limit the tags that he has split to those that are specified in the array. Pretty straight forward, to use a variable value in a regular expression, you first need to build it as a string, and then convert. Something like the following:
var exp:String = 'start-exp' + someVar + 'more-exp'; var regex:Regexp = new RegExp(exp);
Pretty straight forward. So when we get closer to this small update, this is what I did. Of course, one big problem was pretty clear.
var exp:String = '/<' + tag + '("[^"]*"|'[^']*'|[^'">])*>/';
Guess what, the wrong line! Better avoid these quotes in a line. Oops, this will break the regex! I was at a dead end. So I opened a link to the language to find out what I can find. The "source" parameter, which I had never used before, caught my eye. It returns a string described as "part of a regular expression pattern". He did a great job with this. Here is the solution:
var start:Regexp = /])*>/ig; var complete:RegExp = new RegExp(start.source + tag + end.source);
You can reduce this for convenience:
var complete:RegExp = new RegExp(/])*>/.source + tag, 'ig');