Is there a more elegant solution to
//teststring is "the weather is nice today"
var myRe = new RegExp("weather","gi")
myRe = myRe.toString();
//myRe is now "/weather/gi"
myRe = new RegExp(myRe.replace(/\//gi,"").slice(0,-2),"gi")
//myRe is /weather/gi again
You can use
eval to get back the regular expression:
var myRe = RegExp("weather", "gi"); var myReString = myRe.toString(); eval(myReString); // => /weather/gi
eval only if you're sure the string is generated from regular expression