Regex Escape Tool – Escape & Unescape Regex Special Characters
Turn any literal string into a safe regex pattern by escaping metacharacters, or unescape a pattern back to plain text. Toggle forward-slash escaping for JavaScript-style /pattern/ literals, inspect a per-character analysis, and copy the result. Free, private, and runs entirely in your browser.
Input & Settings
Escape modeOutput
Escaped pattern| Char | Code point | Escaped | Count |
|---|
Regex special characters reference
These are the characters that this tool escapes. Any character not in this list is left alone, because it has no special meaning to the regex engine.
| Char | Escaped | Name | Meaning in regex |
|---|
What does a regex escape tool do?
Regular expressions reserve a small set of characters for syntax. A dot . means "any character," an asterisk * means "zero or more of the previous token," and parentheses ( ) create capture groups. If you want those characters to match themselves — a literal period at the end of a sentence, an asterisk in a filename, a question mark in a URL — you have to escape them with a backslash first.
This tool does that escaping for you. Paste any literal string and it returns the same string with a backslash added before every regex metacharacter, so the result can be passed straight into new RegExp(), re.compile(), or any other regex constructor and will match your original text exactly.
Unescape mode goes the other direction: it removes a single backslash that sits immediately before a metacharacter. It deliberately leaves sequences like \d and \n alone, because those are meaningful regex tokens, not escaped literals.
When you need to escape a string for a regex
Escaping comes up whenever user input or arbitrary text has to be embedded inside a pattern. The most common situations:
- Literal string search. You want to find every occurrence of a specific string — a product code, a filename, a log message — inside a larger body of text. Escaping the search string first prevents a stray
.or*from turning your literal search into an unintended wildcard match. - User-supplied search terms. When a user types into a search box and you build a regex from their input, escaping is a security measure: without it, a malicious input like
.*would match everything, and a pattern like(?:could crash the regex engine. - Dynamic replacement patterns. Some replacement functions treat
$and backslash specially in the replacement string. Escaping the literal replacement text first avoids mangled output. - Building a pattern from configuration. When a regex fragment comes from a config file or database column, escaping ensures it's treated as a literal instead of being parsed as syntax.
In all of these cases, the pattern you actually want is "match this exact text," and the escape function is what makes that happen.
Why forward slashes are a special case
In JavaScript, a regex can be written two ways: as a literal /pattern/flags or by calling new RegExp('pattern', 'flags'). Inside the literal syntax, a forward slash / is the delimiter — it marks where the pattern ends. So any literal slash inside the pattern must be escaped as \/, even though a slash has no special meaning to the regex engine itself.
Inside new RegExp(), the slash is just an ordinary character and needs no escaping. Python, PHP, Java, and most other languages don't use slash-delimited regex literals at all, so slashes never need escaping there.
The Escape forward slashes toggle exists for exactly this distinction. Turn it on if the output will be pasted into a /.../ literal. Leave it off if you're using a constructor, a string pattern, or a non-JavaScript language. When in doubt, leave it off — an escaped slash inside a non-literal context still works (it matches a slash), it just looks noisy.
Frequently asked questions
., *, +, ?, (, ), [, ], {, }, ^, $, | and backslash itself — so the pattern engine treats them as literal characters instead of syntax. It's the standard way to safely embed user input or literal strings inside a regex.., *, +, ?, ^, $, {, }, (, ), |, [, ], and backslash itself. Inside character classes, the caret (when first), hyphen, and closing bracket also matter, but this tool handles the common outside-class case./pattern/flags. In that syntax a bare / terminates the pattern, so it must be escaped. If you're using the RegExp constructor or another language's regex function, slashes usually don't need escaping.\. becomes . and \\ becomes \. It does not touch backslash sequences like \d or \n because those are meaningful regex tokens, not escaped literals.\d, the result is \\d, which unescapes back to \d correctly. But if you escape \n, the result is \\n, which unescapes to \n — same characters, but the intent of the original may have been a newline token, so context matters./.../ literals. Turn the slash toggle off if you're not using that syntax.new RegExp() in JavaScript, or to the equivalent function in your language, and it will match the input literally.