In terms of pattern interpretation, there's no difference between the following forms:
/pattern/
new RegExp("pattern")
If you want to replace a literal string using the replace
method, I think you can just pass a string instead of a regexp to replace
.
Otherwise, you'd have to escape any regexp special characters in the pattern first - maybe like so:
function reEscape(s) {
return s.replace(/([.*+?^$|(){}\[\]])/mg, "\\$1");
}
// ...
var re = new RegExp(reEscape(pattern), "mg");
this.markup = this.markup.replace(re, value);