Developer Tools
Regex Escape and Unescape Tool
Escape regex metacharacters such as . * + ? ( ) [ ] with JavaScript, PHP preg_quote, Python re.escape, Go or grep rules, join terms into (?:a|b) or unescape.
How to use Regex Escape and Unescape Tool
Paste the literal text you want to match and pick your regex flavour. The escaped pattern appears instantly with a usage example; options join several lines into one alternation, escape / or double the backslashes for string literals.
- Paste the literal textEnter text such as file[1].txt or Price (USD): $9.99+, or one search term per line.
- Choose the flavourSelect JavaScript / Java / C#, PHP / PCRE, Python, Go or grep / sed basic regex.
- Add options and copyJoin lines as alternatives, escape / for /…/ literals, or output a string literal, then copy the pattern.
How the regex flavours differ
JavaScript, Java, C# and Go escape the classic metacharacters \ ^ $ . * + ? ( ) [ ] { } |, so file[1].txt becomes file\[1\]\.txt. PHP's preg_quote also escapes = ! < > : - # and the / delimiter, and Python's re.escape additionally escapes - & ~ # and whitespace, so a-b c#1 becomes a\-b\ c\#1. grep and sed basic regular expressions only treat \ ^ $ . * [ ] as special, so parentheses, braces and plus signs are left alone there. Each result comes with a ready-made example such as re.compile(r"…") or preg_match('/…/', $text).
Alternations and string literals
Tick Join lines as alternatives and each line is escaped, duplicates are removed and longer terms go first, so a.b, c+d and longer* become (?:longer\*|a\.b|c\+d) and a short term cannot match before a longer one. For grep the group is written as \(…\|…\), a GNU extension. If the pattern will sit inside an ordinary string, for example new RegExp("…") or a Java string, tick Output as a string literal to double every backslash, so a.b becomes a\\.b. Unescape mode removes backslashes before symbols while keeping escapes such as \d and \w intact.
Accuracy and data handling
Validate the result with your project's own tests and runtime rules before using it in production. The calculation runs in your current browser; the tool code does not send the input to a processing API.
FAQ
Why escape regex metacharacters?
Characters such as . and * have special meanings: . matches any character, so the pattern a.b also matches axb. Escaping it as a\.b makes the regex match only the literal text.
How do I use the result in JavaScript?
Use it directly in a literal such as /file\[1\]\.txt/. With new RegExp(), tick Output as a string literal, otherwise the string swallows one level of backslashes.
Can I reverse the escaping?
Yes. Choose Unescape and backslashes before punctuation are removed, so a\.b becomes a.b, while letter escapes such as \d and \w are left unchanged.
More Developer Tools
Related toolsTranslate text into binary code and binary back into readable text
Build or decode HTTP Basic authentication headers in your browser
See whether a JWT is valid, expired or not yet valid, and how long is left
Create secure, URL-safe Nano IDs with your own length, prefix and alphabet
Create time-sortable ULIDs in bulk, for now or for a chosen time
Sign test JWTs with HS256, HS384 or HS512 and automatic iat and exp