Live regex matching with groups, flags and a replace preview
Regex Escape
Turn any text into a pattern that matches it exactly, without hunting for which characters need a backslash.
Loading tool…
How to use regex escape
Type or paste the text you want to match exactly.
Choose the output: a bare pattern, a /literal/, a string for new RegExp() or a character class.
Optionally treat each line as one alternative, or anchor the pattern with ^ and $.
Copy the result, or open it in the regex tester.
What this tool does
- Escapes the characters with special meaning in a pattern: \ ^ $ . * + ? ( ) [ ] { } and |.
- Escapes / as well when you need a /literal/ in code, and doubles backslashes for a string.
- Builds an alternation from a list of lines, such as a set of words or file names.
- Builds a character class from your characters, escaping the four that matter inside brackets.
How the result is verified
The escaped pattern is compiled with the Unicode flag and tested against your text: it must match each input completely, or the check shows a warning.
Frequently asked questions
Does JavaScript have a built-in escape function?
Newer browsers are adding RegExp.escape, but it is not available everywhere yet. This tool gives you an escaped pattern you can paste into any code today.
Why is the string version full of double backslashes?
Inside a JavaScript string a backslash must itself be escaped, so \. in a pattern becomes "\\." in a string passed to new RegExp().
Is my data uploaded to a server?
No. Everything you drop, paste or type is processed by code running in this browser tab. You can check it yourself: open your browser's developer tools, watch the Network panel, and use the tool. No request carries your data.
Related tools
Tested regular expressions for emails, URLs, dates, IDs and more
Split text on any regex, trim pieces and export as lines, JSON or CSV
Pull every match or capture group into a list, deduplicated and sorted