Escape text so a regex matches it literally in JavaScript, Python, PHP, Java, Go or .NET
Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.Regex escaping puts a backslash before each character with a special meaning, so a pattern matches the text literally. The 14 characters to escape almost everywhere are . ^ $ * + ? ( ) [ ] { } | and the backslash. Each language adds a few more, and JavaScript and Java escape differently.
Paste the text the pattern must match exactly, or click Try an example.
Choose the language: JavaScript, Python, PHP, Java, Go, .NET or sed and grep.
Turn on One per line to match any one of several lines, joined with |.
Click Copy, or press Ctrl+Enter, and paste the pattern into your code.
In a regular expression, a dot means any character, a plus means one or more, and brackets start a set. To search for text that contains them, such as a price like $4.99 or a file name like report(1).pdf, every such character must be escaped. This tool does it the way each language's own escape function does, so the pattern behaves exactly as in your code.
| Language | Function it matches | Notes |
|---|---|---|
| JavaScript | RegExp.escape |
also escapes / and punctuation as \x codes; works with the u and v flags |
| Python | re.escape |
only special characters, since Python 3.7 |
| PHP | preg_quote($s, '/') |
adds = ! < > : - # and the / delimiter |
| Java | Pattern.quote |
wraps the text in \Q and \E |
| Go | regexp.QuoteMeta |
the smallest set: \ . + * ? ( ) | [ ] { } ^ $ |
| .NET | Regex.Escape |
also spaces and #, for patterns that ignore white space |
| sed, grep | POSIX basic syntax | . [ \ * ^ $ and the / delimiter |
One per line. Turn it on to escape each line separately and join them with |, so the pattern matches any entry in a list of words, URLs or file names. Blank lines and duplicates are dropped. In sed and grep the join is |, which GNU tools understand.
Proof, not trust. For JavaScript, the page runs the pattern in your browser's own engine and confirms it matches the text and nothing else. The JavaScript output is tested against the engine with and without the u and v flags, and the Python output against CPython's re.escape on 728 strings.
Putting the pattern inside a string literal is a second, separate step: a backslash in a Java or C# string must be doubled. The String Escape tool does that part.
Everything runs in your browser; nothing you paste is sent anywhere.
The characters with a special meaning: . ^ $ * + ? ( ) [ ] { } | and the backslash itself. Inside a pattern they act as wildcards, anchors, repeats or groups, so a literal dot must be written \. and a literal plus \+. Some languages escape a few more, such as / in JavaScript and PHP, or spaces in .NET.
Write a backslash before it: \. matches only a dot, while a bare . matches any character. So example.com as a pattern also matches examplexcom, and example\.com matches only the real domain. Inside square brackets a dot is already literal, so [.] works too.
RegExp.escape writes a leading letter or digit, and punctuation such as - , = and spaces, as \x codes, so the result stays correct wherever it is inserted: after \0 or \c, inside a character class, or with the u and v flags. The pattern is longer but always matches the text literally.
Both put a backslash before special characters, but PHP's preg_quote also escapes = ! < > : - # and the delimiter you pass, usually /, and writes a NUL byte as \000. Python's re.escape escapes - & ~ # and white space as well. Each tool's output is valid only for its own engine.
Pattern.quote wraps the text in \Q and \E, which tell Java's engine to read everything between them literally. If the text itself contains \E, Java closes the quote, adds an escaped \E and opens a new one. To use the result in Java source code, every backslash must then be doubled in the string literal.
Escape each word and join them with a vertical bar: cat|dog|bird matches any of the three. Turn on One per line here, paste the list and every line is escaped and joined for you, with blank lines and duplicates dropped. Add ^( and )$ around it to match whole lines only.
Rates and rules change; check the source before you rely on a figure.
Still stuck? Ask about Regex Escape and anybody who knows can answer. No account needed.
Open it set for: Python Regex Escape (re.escape) · List to Regex.
Same job, other tools: Query String Parser – Split a URL query string into a table of decoded parameters.
On the related tools: TSV to JSON – Convert tab-separated values, such as a paste from Excel, into JSON.