RegExp. quoteText()

Axel Rauschmayer axel at
Wed Aug 28 08:23:59 PDT 2013

This must have been suggested before, but it would be great to have a built-in function for quoting text in a RegExp.

For example:

RegExp.quoteText = function (text) {
    return text.replace(/[\^\$\\.*+?()[\]{}|]/g, '\\\$&');


If you wanted to be extra thorough, you could include parens, braces and brackets.

Dr. Axel Rauschmayer
axel at


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list