About this tool
Characters such as . * + ? ( ) [ ] { } | ^ $ and backslash have special meaning in a regular expression. This tool puts a backslash in front of each one so your text, a file path, a price or a URL, is matched exactly as written. It can also wrap the result as a /…/ literal, produce a quoted string for new RegExp(), or turn a list of lines into one alternation.
How to use Regex Escape
- Paste the literal text.
- Choose how you want the output formatted.
- Copy the escaped pattern into your code.
Frequently asked questions
Why does a string for new RegExp() have double backslashes?
The string literal consumes one level of backslashes, so \. in a pattern must be written "\\." inside quotes.
Is the output safe with the u flag?
Yes. Only characters that are valid to escape in Unicode mode are escaped, so the pattern works with or without u.