Regex Escape
Make any text safe to use inside a regular expression. Characters like . * + ? ( ) [ ] { } ^ $ | are escaped with the exact rules of your language — JavaScript, Python, PHP, Java, .NET or Go — so the pattern matches the text literally.
word1|word2|word3.Testing the pattern next? Regex Tester →Why Escape Text for a Regex?
Some characters have a special meaning in regular expressions.
In a regular expression, . means “any character”, * means “repeat”, ( ) make a group and so on. If you build a pattern from user input or a fixed string — say, to find $9.99 — those characters must be escaped with a backslash, or the regex will match the wrong things or fail to compile.
Each language escapes slightly differently. This tool follows the actual rules of each one: re.escape in Python 3.7+, preg_quote in PHP 7.3+, Regex.Escape in .NET and regexp.QuoteMeta in Go. For JavaScript and Java it escapes exactly the regex syntax characters, so the JavaScript result works with or without the u and v flags.
Inside [ ]. Inside a character class, only \ ] [ ^ - are special (plus & in Java, and ( ) { } / | with JavaScript's v flag). Choose Inside [ ] to escape just those. With the v flag, also avoid doubled punctuation such as && inside [ ] — it's reserved there.
Code string. In Java, C# and other languages a regex is usually written inside a string literal, so the backslashes must be escaped again. Code string gives you a ready-to-paste literal: /…/ for JavaScript, r'…' for Python, '/…/' for PHP, "…" for Java, @"…" for C# and `…` for Go.
What Each Language Escapes
Characters escaped in “In a pattern” mode.
| Language | Escaped characters | Built-in equivalent |
|---|---|---|
| JavaScript | \ ^ $ . * + ? ( ) [ ] { } | / | Safe for literals, new RegExp() and the u / v flags |
| Python | ( ) [ ] { } ? * + - | ^ $ \ . & ~ #, space and \t \n \r \v \f | re.escape() (3.7+) |
| PHP | . \ + * ? [ ^ ] $ ( ) { } = ! < > | : - # /, NUL → \000 | preg_quote($s, '/') |
| Java | \ ^ $ . | ? * + ( ) [ ] { } | Same result as Pattern.quote() |
| .NET / C# | \ * + ? | { [ ( ) ^ $ . #, space → \ , tab/newline → \t \n \r \f | Regex.Escape() |
| Go | \ . + * ? ( ) | [ ] { } ^ $ | regexp.QuoteMeta() |
How to Use the Regex Escape
Get your result in under ten seconds.
Paste the literal text
The exact text the regex should match.
Pick language & position
Your regex flavour, and whether it goes inside [ ].
Copy the pattern
As a bare pattern, or as a ready-to-paste code string.
Why Use the Regex Escape on Developers Web Tools
Fast, accurate and private — built for developers.
Six flavours
JavaScript, Python, PHP, Java, .NET and Go — each with its own exact rules.
Character classes
A separate mode that escapes only what's special inside [ ].
Code strings
Backslashes doubled where the language needs it — no more \\\\ guesswork.
Word lists
Escape many lines at once and join them into one alternation.
Verified
Outputs are tested against the languages' own escape functions.
Private
Runs entirely in your browser.
Frequently Asked Questions
Outside a character class: \ ^ $ . | ? * + ( ) [ ] { } in almost every flavour. Inside [ ]: only \ ] ^ - (and [ in some flavours). Some languages escape more, such as / in JavaScript literals or # and spaces in Python and .NET.
With JavaScript's u or v flag, escaping a character that isn't special (like \- outside a class) is a syntax error. This tool escapes only syntax characters, so the result works with and without those flags.
In Java source code, the regex is inside a string literal, and string literals use backslash escapes too. The regex \. must be written as "\\.". Choose Code string to get that automatically.
It matches exactly the same text. Pattern.quote() wraps the string in \Q…\E; this tool uses backslashes, which is easier to read and to combine with other pattern parts.
Yes: turn on Each line separately and Join lines with |. Put longer words first if one word is the start of another (e.g. cats|cat).
No. Everything runs in your browser.