Regex Escape Tool

Paste any text, such as a price with a dot, a file path, a URL or a phrase with brackets, and get a version you can drop into a regular expression where it will match exactly that text. Choose the style for your language, or put one term per line to get a single pattern that matches any of them.

Tool

Builds (?:term1|term2|...) to match any of them

45 characters

Escaping runs in your browser. What you type never leaves this device.

Features

  • Escapes every regex special character: . * + ? ^ $ { } ( ) [ ] | \ and /

  • Styles for JavaScript (also fine for Java, C# and Go), PHP preg_quote, Python re.escape and grep -E / awk

  • A mode for text that goes inside [ ] brackets, where only ] \ ^ and - need escaping

  • One term per line becomes (?:term1|term2|...), longest first so longer phrases win

  • JavaScript output works with and without the u (Unicode) flag

When you need to escape text for a regex

Searching for a fixed string

A pattern for ₹1,299.00 or file(1).pdf breaks because . ( and ) mean something to the regex engine. Escaping turns them back into plain characters.

Matching a list of words

Paste city names, product codes or blocked words one per line and get one pattern that matches any of them, for a search, a filter or a validation rule.

Building patterns in code

Check what your language's escape function would produce, or copy the escaped text straight into a pattern in a config file or spreadsheet formula.

Escaping in different regex flavours

Which characters are special

Outside brackets, the characters with special meaning in almost every flavour are . * + ? ^ $ { } ( ) [ ] | and the backslash. The JavaScript style also escapes / so the result can sit inside a /pattern/ literal. A hyphen is only special inside [ ], so it is left alone outside brackets.

Flavour differences

  • PHP preg_quote also escapes = ! < > : - and #, which matters in some PCRE modes and delimiters.
  • Python re.escape escapes spaces, # & ~ and -, so patterns stay correct in verbose mode.
  • grep -E and awk use POSIX extended syntax: the same core set, without the / escape.
  • Inside a character class such as [abc], only ] \ ^ and - have special meaning.

Then test it

Paste the escaped pattern into the Regex Tester with some sample text to confirm it matches what you expect, or use the Regex Match Extractor to pull every match out of a document.

Regex Escape Tool - FAQ