Y
Yansky
Hi, if I have a string assigned to a variable, how can I use that
variable in a regex?
e.g. I would like to do something like this:
var words = 'the quick brown browning fox';
var key = getKey();
var patt=/\bkey\b/;
patt.test(words);
Unfortunately I can't just put the string I'm searching for directly
in the regex, because it will be changing each time this bit of the
script is run.
Any help would be appreciated.
Cheers.
variable in a regex?
e.g. I would like to do something like this:
var words = 'the quick brown browning fox';
var key = getKey();
var patt=/\bkey\b/;
patt.test(words);
Unfortunately I can't just put the string I'm searching for directly
in the regex, because it will be changing each time this bit of the
script is run.
Any help would be appreciated.
Cheers.