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· Your data stays in your browser.
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?
- Paste the literal text you want to match.
- Choose the regex flavor and, optionally, a wrapper (/pattern/ literal or "string").
- 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:
price: $5.00 (approx.) [ok]? a+b*c | d\e
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.
Related tools
Regex Tester
Write a pattern, paste some text and see every match highlighted, with its position and capture groups.
Developer Tools
Regex Replace
Rewrite text with a regex pattern and a replacement template that can reuse the captured pieces.
Developer Tools
Regex Match Extractor
Pull every piece of text that matches a pattern out of a long document and get it as a tidy list.
Developer Tools
JSON Escape
Turn any text, even a whole JSON document, into a safe string you can embed inside another JSON value.
JSON & Data
HTML Entities Encoder
Escape markup characters, or turn every non-ASCII character into an entity such as é or é.
Encoding & Decoding
URL Encoder
Make any text safe for a URL: spaces, accents, ampersands and emoji become %XX sequences.
Encoding & Decoding
Find and Replace
Search a block of text and replace every occurrence, as plain text or with a regular expression and capture groups.
Text Tools