dresden_phoenix — 2011-01-10T18:39:58-05:00 — #1
I have seen RegExp() object being used in some script... BUT I also have seen this being used instead: cls=/ain/gi;
What is the advantage of using an object instead of a simple variable as above?
and at the risk of answering my own question, is there a way to use a variable INSIDE a regex expression when NOT using the RegExp() object?
something like this...
As always .. advice is appreciated and thanks in advance
paul_wilkins — 2011-01-10T19:03:26-05:00 — #2
Not unless you want mobs of people screaming "eval is evil!!!" in your ear.
You'll need the RegExp constructor for that.
When using the constructor, since normal string escape rules apply, you'll also need to escape occurrences of the backslash.
cls = new RegExp('(\\\\s|^)' + VariableHere + '(\\\\s|$)', 'gi');
dresden_phoenix — 2011-01-10T19:40:01-05:00 — #3
Thanks Paul! I think I get it now.