Skip to content

Regex Escape

Turn any literal text into a safe regex pattern by escaping the characters that have a special meaning, or reverse it.

Processed locally in your browser

Options
0 chars · 0 lines
The result will appear here.

What is Regex Escape?

Characters such as . * + ? ^ $ { } ( ) | [ ] \ have a special meaning in a regular expression. To match them literally (a price like $5.00, a file name with dots, a user-provided search term) they must be escaped with a backslash.

This tool escapes the right set of characters for your regex flavor: JavaScript, PCRE/PHP (like preg_quote), Python (like re.escape) or Java/.NET. Line breaks and tabs become \n and \t. You can wrap the result as a /pattern/ literal or as a double-quoted string with doubled backslashes, ready to paste into code. Unescape mode removes the backslashes before punctuation, including \Q…\E quoting.

How does it work?

  1. Paste the literal text you want to match.
  2. Choose the regex flavor and, optionally, a wrapper (/pattern/ literal or "string").
  3. Copy the escaped pattern, or switch to Unescape to turn an escaped pattern back into plain text.

Common use cases

  • Searching for user input or a fixed phrase inside a regex without it being interpreted.
  • Building a pattern from a file path, URL or price such as $5.00 (approx.).
  • Converting a literal into the exact form expected by JavaScript, PHP or Python code.
  • Reading an escaped pattern by removing its backslashes.

Examples

Try this input in the tool above:

Input
price: $5.00 (approx.) [ok]? a+b*c | d\e
Output
price: \$5\.00 \(approx\.\) \[ok\]\? a\+b\*c \| d\\e

Privacy

Regex Escape runs entirely in your browser. The text or files you provide are processed on your device and are not uploaded, logged or stored on our servers.

Limitations

Escaping makes text match literally; it does not build a complex pattern for you. Flavors differ, so always test the result in your target engine.

Frequently asked questions

Which characters are escaped in JavaScript?

The characters \ ^ $ . * + ? ( ) [ ] { } | and the forward slash. Hyphens are left alone because escaping them is invalid outside a character class in unicode mode.

How does the Python flavor differ?

It follows re.escape: it also escapes spaces, hyphens, #, &, ~ but leaves characters like _ and / as they are.

What does the "string" wrapper do?

It doubles every backslash and escapes double quotes so the pattern can be pasted between quotes in a string literal.

More tools in Developer Tools →