We all know that to match a particular regular expression in JS, you simply do this:
However, if you want “foo” to be a variable:
var foo = 'foo'; "foo".match(/foo/i);
This becomes confusing and I don’t think it works.
To do it properly, do the following instead:
var filter = new RegExp('foo'); "foo".match(filter);