I would like to dynamically create the Regular Expression in the code below, by working out the permutations I need to detect for, then creating the Regular Expression like concatenating a string, but no matter what I try it fails.
I've found that if you trace testRX.source, you can see the regexp without escape characters ( thats what I believe anyway ).
Ideally I would like to do this
var permutationsString:String = "abc|acb|bac|bca|cab|cba";
var regex1:RegExp = "/\b("+permutationsString+")\b/g";
regex1.test( "whatever" );
but it does not work.
Here's working code below
var testRX:RegExp = /\b(abc|acb|bac|bca|cab|cba)\b/g;
var regex:RegExp = new RegExp( testRX );
trace( "regex.test = " + regex.test( "333" )); // false
trace( "regex.test = " + regex.test( "abc" )); // true
trace( "regex.test = " + regex.test( "ca" )); // false
trace( "regex.test = " + regex.test( "bbb" )); // false
trace( "regex.test = " + regex.test( "abce")); // false
This is Actionscript 3.
Thanks in advance.
gingerman