This regex escape tool turns plain text into a pattern that matches that exact text and nothing else. Paste a price, file path, URL or code snippet, pick your regex flavor, and every special character gets a backslash where that engine needs one. It saves developers and testers from the stray dot that matches the wrong line.
-
Runs entirely in your browser — nothing is uploaded. The output is the pattern itself; if you paste it into a quoted string in code, that language may need the backslashes doubled.
How the Regex Escape Tool Works
Regular expressions reserve a small set of characters for syntax. A dot means any character, a plus means one or more, and a bracket opens a character class. To match those characters as themselves, each one needs a backslash in front. The tool adds a backslash only where the chosen engine expects one, because the flavors disagree on the exact list. It is the quickest way to escape string for regex use when the text comes from a user, a file name or a database.
Formula: output = input with every character c replaced by \c when c is in the flavor’s special set. JavaScript set: . * + ? ^ $ { } ( ) | [ ] \. Python 3.7+ set: the JavaScript set plus – & ~ # and whitespace. PHP preg_quote set: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : – # plus the / delimiter. .NET set: \ * + ? | { [ ( ) ^ $ . # and whitespace, where a space becomes a backslash-space and tab, newline, carriage return and form feed become \t, \n, \r and \f. Java: \Q + input + \E, with any \E already inside the text split out so it cannot end the quote early.
- Text to escape — the literal string you want to match. Multi-line input is fine.
- Regex flavor — JavaScript, Python, PHP / PCRE, .NET (C#) or Java. Pick the engine that will run the pattern.
- Escape each line and join with | — turns a list of words into one alternation pattern; blank lines are skipped.
Example Scenarios
| Flavor | Input | Escaped output | Escaped count |
|---|---|---|---|
| JavaScript | price: $9.99 (USD)? | price: \$9\.99 \(USD\)\? | 5 |
| Python | a+b=c [v2] | a\+b=c\ \[v2\] | 4 |
| PHP / PCRE | a+b=c [v2] | a\+b\=c \[v2\] | 4 |
| .NET / C# | C:\temp\*.log | C:\\temp\\\*\.log | 4 |
| Java | 1+1=2 | \Q1+1=2\E | Quoted |
| JavaScript, lines joined | a.b and c|d on two lines | a\.b|c\|d | 2 |
Escape Regex Special Characters Without Breaking Your Code
The output of the regex escape tool is a pattern, not a string literal. When you paste the pattern into a quoted string in Java, C# or Python, the language’s own string rules apply first, so every backslash must be doubled unless you use a raw string such as r’…’ in Python or a verbatim @ string in C#.
- In JavaScript, build the pattern with new RegExp(escaped). If you paste it into a /…/ literal instead, also put a backslash before any forward slash.
- Never run a regex escaper twice on the same text. The second pass escapes the backslashes from the first and the pattern stops matching.
- Replacement strings follow other rules: $ is special in JavaScript replacements and \ in Python ones, while a dot is not.
- Escaping does not change case sensitivity; add the i flag if Price and price should both match.
Some websites that offer regex escape online send your text to a server. This one works in your browser, which matters for private file paths or logs. For the full list of special characters and flags, see MDN’s guide to regular expressions in JavaScript.
Regex Escape Tool FAQ
Is this escaper free, and does it upload my text?
Yes. It is free, needs no account and works in any modern browser on a desktop or phone. All the escaping happens in JavaScript on your own device, so file paths, passwords or private log lines you paste are never sent anywhere.How do I escape a string in Python before using it in a pattern?
Call re.escape(text) from the standard re module. Since Python 3.7 it escapes only characters that have a meaning in a pattern, plus whitespace, which is exactly what the Python option here reproduces. Use a raw string such as r’\d+’ for the parts you write by hand.What is the C# equivalent of a regex escape tool?
.NET provides Regex.Escape in System.Text.RegularExpressions. It escapes the backslash, asterisk, plus, question mark, pipe, opening brace, opening bracket, both parentheses, caret, dollar sign, dot, hash and white space. Closing brackets and braces are left alone because they only matter after an opening one. Our .NET option follows those same rules.Which characters are special in regular expressions?
In nearly every flavor the core set is the dot, asterisk, plus, question mark, caret, dollar sign, pipe, backslash, parentheses, square brackets and curly braces. Some engines escape more: PHP’s preg_quote adds = ! < > : – and #, and Python adds whitespace. Letters and digits are never escaped, because a backslash gives them a new meaning.Why does my escaped pattern still not match?
Usually the programming language consumed the backslashes before the regex engine saw them. In an ordinary quoted string, a backslash-dot often becomes a plain dot. Use a raw or verbatim string, or double each backslash. Also look for trailing spaces, tabs or curly quotes copied from a document.When should I use \Q and \E instead of backslashes?
Java, PCRE and Perl support \Q…\E, which treats everything between the markers as literal text. It keeps long strings readable and is exactly what Java’s Pattern.quote returns. JavaScript, Python and .NET do not support it, so they need one backslash per special character. The regex escape tool produces both styles from the same input.Related Tools
Validation testing often covers passwords, and the password strength calculator for entropy checks shows how long a random password really is. Regex work on IDs and flags gets easier with the binary to decimal converter for bit masks, and the subnet calculator for IP address ranges helps before you write a pattern that matches network addresses. Keep the regex escape tool open next to them.