Developer ToolsA little help for every day

Search by name or task, such as JSON or percentage.

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.

View all tools
ResultUpdates as you type
Price \(USD\): \$9\.99\+
file\[1\]\.txt

Example: /Price \(USD\): \$9\.99\+ file\[1\]\.txt/

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.

  1. Paste the literal textEnter text such as file[1].txt or Price (USD): $9.99+, or one search term per line.
  2. Choose the flavourSelect JavaScript / Java / C#, PHP / PCRE, Python, Go or grep / sed basic regex.
  3. 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.

Often Used Together

Next step

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 tools