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
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');
Thanks Paul! I think I get it now.