Skip to content
OnlineToolStudio

Regex Escape

runs in your browserno sign-upfree

Escape text so it can be used literally in a regular expression — the same result as preg_quote() in PHP, re.escape() in Python or Pattern.quote() in Java.

Paste the result into a pattern to match the text exactly — or try it in the Regex Tester.

About this tool

Regex Escape turns any text into a pattern that matches exactly that text, by putting a backslash before characters that have a special meaning: . * + ? ^ $ ( ) [ ] { } | \ and /. Choose your language and the output is the same as its own function — preg_quote() in PHP, re.escape() in Python, Pattern.quote() in Java — so you can paste user input or file names into a regex safely.

How to use

  1. Choose your language.
  2. Type or paste the text you want to match literally.
  3. Copy the escaped result into your pattern.

FAQ

Why escape text before putting it in a regex?

Characters like . and + have special meanings, so searching for "1+1" with the pattern 1+1 matches "11" instead. Escaped, 1\+1 matches only "1+1". Always escape user input before building a pattern from it.

Why does the result differ between languages?

Each language escapes a slightly different set of characters: PHP’s preg_quote also escapes = ! < > : - # and the / delimiter, Python’s re.escape escapes spaces and & ~ #, and Java wraps the text in \Q…\E. Each result is exactly what that language’s own function returns.

Related tools

All tools