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 mode
Escape mode: Adds a backslash before every regex metacharacter so the pattern matches your text literally. Switch to Unescape to remove those backslashes.

Output

Escaped pattern
Input chars
0
Output chars
0
Escaped
0
Escaped pattern
Escaped characters 0 escaped
CharCode pointEscapedCount

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.

CharEscapedNameMeaning 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

A regex escape tool adds backslashes before characters that have special meaning in regular expressions — like ., *, +, ?, (, ), [, ], {, }, ^, $, | 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.
In JavaScript and most PCRE-style engines, the metacharacters that need escaping outside character classes are: ., *, +, ?, ^, $, {, }, (, ), |, [, ], 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.
Only if your pattern will be written inside a JavaScript-style regex literal like /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.
Unescape removes a single backslash that appears immediately before a regex metacharacter. For example, \. becomes . and \\ becomes \. It does not touch backslash sequences like \d or \n because those are meaningful regex tokens, not escaped literals.
For plain literal text, yes — escaping then unescaping returns the original string. But escaping is lossy when the input already contains backslash sequences that look like regex tokens. If you escape the string \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.
Yes. The core set of regex metacharacters is the same across JavaScript, Python, PHP, Java, Go, Ruby, and most PCRE-style engines. The only language-specific difference is the forward slash, which is only special inside JavaScript-style /.../ literals. Turn the slash toggle off if you're not using that syntax.
Yes. Paste the string, leave the slash toggle off, and copy the escaped output. Pass it directly as the first argument to new RegExp() in JavaScript, or to the equivalent function in your language, and it will match the input literally.
Absolutely. Everything runs in your browser. The text you paste never leaves your device — there is no server processing, no logging, and no data storage.
Yes. The tool is fully responsive and works on phones, tablets, and desktops.
Yes. Once the page loads, the escape and unescape functions work without an internet connection. All processing happens locally in your browser using JavaScript.