Escaping Strings for Use in Regular Expressions Feb 08, 2010 I looked around on the web and found a few suggestions, but I like this the best: String.prototype.escapeRegex = function() { return this.toString().replace(/([\[|\\|\^|\$|\.|\||\?|\*|\+|\(|\)])/gm,"\\$1"); };