Regex Escape

Escape special regex characters for literal string matching.

Escape text so it can be used literally inside a regular expression. Characters with special meaning (. * + ? ^ $ { } ( ) | [ ] \ and, optionally, /) get a backslash in front, so "price (USD) $5.00" matches exactly that text instead of being read as a pattern. Paste a file name, a URL or any user input you want to match exactly.

Common use cases

  • Search for a literal string that contains dots or brackets
  • Build a pattern from user input safely
  • Match a file name or URL exactly

How to use

  1. Paste the text.
  2. Leave Escape / ticked if you're writing a /pattern/ literal.
  3. Copy the escaped text into your regex.

FAQ

Why did my regex match too much?

Unescaped characters such as . match anything. example.com also matches exampleXcom unless the dot is escaped as \.

Where can I test the result?

Paste it into the regex tester.