I am using RegExp on a pattern after reading it from a json file.
json file :
patternToSearch : {
"test" : "/^test/g"
}
In js file I am using this pattern to match with a string
var patternToMatch = "testing";
var pattern = new RegExp(file.patternToSearch[test]);
console.log(pattern.test(patternToMatch);
I get the output as false as instead of /^test/g the pattern is coming out as /\/^test\/g/.
Not able to remove the extra slahes. Could somebody help me out in this?
['test']I guess test here should be a string instead of a variable.