I have the following code, which works, but I need to inject some different stuff into the regular expression object (regex2) at runtime. However, text.replace
regex2
You can make a regular expression object from a string using the RegExp constructor function:
var regExp = new RegExp(myString); // regex pattern string text.replace(regExp, '');