in plain javascript: I am getting error when i run the below:
var arg_regex = 'myregex:/^[:a-z0-9\s!\\\/]+$/i';
regex_patt = arg_regex.replace(/^myregex:/,'');
if(regex_patt.test(stringtocheck)){
//good
} else {
//bad
}
error:
regex_patt.test is not a function
pl help. not able to figure why it would fail.
What Felix said:
The RegExp object must be constructed from the string first.
In the above example, you’re replacing a static string, so you can use
string.replace('staticTextToRemove','')or use thesplitandjoinshown above.I’ve heard
split().join()is slightly more performant… and its a neat trick.