← All text tools

Regex Escape Tool

Escape the special characters of a plain string so it matches literally in a regular expression, for JavaScript, Python, Java, PHP and .NET.

  • Free
  • No sign-up
  • Works on any device

About Regex Escape Tool

When a search term comes from a user or a file, characters like the dot, plus and parentheses change what a regular expression means. Escaping puts a backslash in front of each special character so the text matches literally. The rules differ between languages, so this tool shows the result for JavaScript, Python's re.escape, Java both as backslashes and as Pattern.quote with \Q and \E, PHP's preg_quote with a delimiter, and .NET's Regex.Escape, plus the Java string literal with doubled backslashes that you can paste straight into source code.

How to use Regex Escape Tool

  1. Type or paste the text that must be matched literally.
  2. Set the PHP delimiter if you use one, and tick the JavaScript option for regex literals if needed.
  3. Copy the escaped pattern for the language you use.

Why use this tool?

Also known as

Frequently asked questions

Which characters does JavaScript escape?

The set used by MDN: . * + ? ^ $ { } ( ) | [ ] and the backslash. Add the slash for regex literals, and the hyphen only when the text goes inside a character class.

Why does Python escape spaces and hyphens?

Since Python 3.7, re.escape escapes characters that can matter in verbose mode or inside a class, including space, hyphen, ampersand, tilde and hash, but not ordinary punctuation.

When should I use Java Pattern.quote instead of backslashes?

Pattern.quote wraps the whole text in \Q and \E, which is shorter and handles any content. Backslashes are better when you need to combine the escaped text with other pattern parts.

Is Regex Escape Tool free?

Yes. Regex Escape Tool on Toolipedia is free to use, with no sign-up and no watermark.

Is it safe to use?

Yes. Everything is worked out in your browser, and nothing you enter is sent to our server.

Does it work on my phone?

Yes. It works in any modern browser on Android and iPhone, as well as on tablets and computers. There's nothing to install.

Do I need an account?

No. Just open the page and use the tool. There's no sign-up and no email needed.

Can I put Regex Escape Tool on my own website?

Yes. Use the Embed on your site button under the tool to copy a short piece of code and paste it into your page. It is free, needs no account, and the tool keeps working inside your page.

Related tools