Skip to content

Home

Escape RegExp

Escapes a string to use in a regular expression.

const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

escapeRegExp('(test)'); // \\(test\\)

More like this

Start typing a keyphrase to see matching snippets.