Regex Escape Tool
Escape every regex special character in plain text so it can be safely embedded inside a regular expression as a literal match.
Plain Text
Escaped for Regex
Escaped text will appear here...
How to Use the Regex Escape Tool
Type or paste any plain text you want to match LITERALLY inside a regular expression. Every regex special character — . * + ? ^ $ { } ( ) | [ ] \ — is automatically prefixed with a backslash so it's treated as a literal character instead of regex syntax, using the standard text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') approach. Toggle the extra option to also escape forward slashes if you're embedding the result inside a JavaScript /pattern/ literal.
Example
The input 3.14 + (a*b)? becomes 3\.14 \+ \(a\*b\)\? — every character that would otherwise have special meaning in a regex is escaped, so the resulting pattern matches that exact literal text and nothing else.
Common Use Cases
- Safely inserting user-supplied or dynamic text into a regex pattern built at runtime.
- Building a "find literal text" search pattern from a string that contains punctuation like parentheses or periods.
- Preparing a filename, URL, or version string (all of which often contain dots) to be matched exactly inside a larger pattern.
FAQs
- How is this different from the Regex Tester or Regex Replace Tester? Our Regex Tester and Regex Replace Tester TEST or apply a regex pattern you already have against sample text. This Regex Escape Tool does something upstream of that — it prepares arbitrary literal text so it can be SAFELY embedded inside a regex pattern without its characters being misinterpreted as regex syntax.
- Why would I need to escape plain text before using it in a regex? Characters like
.,*, and(have special meaning in regular expressions. If you insert unescaped user input or a dynamic string containing those characters directly into a pattern, it can match unintended text or throw a syntax error — escaping first guarantees it's treated as literal text. - Do I need to escape forward slashes too? Only if you're building a JavaScript regex literal written between two slashes, like
/pattern/— in that context an unescaped/would end the pattern early. If you're passing a string tonew RegExp(pattern)instead, forward slashes don't need escaping.
