To simplify quoting in regular expressions, you can use the following code:
RegExp.quote = function(str) { return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); };
Then you apply it like this:
var expr = RegExp.quote('../../libs/bootstrap/less'); mystring.replace(new RegExp(expr, 'g'), 'bootstrap');
source share