Regex Escape

Paste the exact text you want to find. You get a pattern that matches it character for character, with every special character escaped.

How it works

In a regular expression, 14 characters have a meaning of their own: ^ $ \ . * + ? ( ) [ ] { } and |. To match one of them as itself, it needs a backslash in front. The tool adds that backslash to each one, and to / as well, because / ends a pattern written in JavaScript.

Nothing else is escaped. Escaping a character that needs none, such as - or a letter, is harmless in some engines and an error in others: JavaScript rejects \- in a pattern with the u flag. These 15 characters are the set every common engine accepts escaped.

Turn on Match any line to escape each line on its own and join them with |, which matches any one of them. Blank lines are skipped. Everything runs on this page.

How to use it

  1. 1 Type or paste the text to match into the first box.
  2. 2 Turn on Match any line if each line is a separate thing to find.
  3. 3 Turn on the verbose option only if your pattern uses the x flag.
  4. 4 Copy the Pattern and paste it into your code or your editor's search.

Good to know

  • In a string in source code, each backslash may need doubling. In Java, a\.b is written "a\\.b". A raw string, such as r"a\.b" in Python, avoids that.
  • Match any line is a quick way to build a pattern from a list of words or file names: one per line in, one alternation out.
  • To match a whole line and nothing more, put ^ before the pattern and $ after it, and use the m flag if the text has several lines.
  • Your editor's search may have a plain text mode. Use that when you do not need a regular expression at all.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Why "$4.99?" needs three backslashes before a regex can find it

A regular expression is a small language, and most of its words are single characters. A dot means any character. A question mark makes the thing before it optional. A dollar sign means the end of the line, and brackets of every kind group or list things. That is convenient when you are writing a pattern, and a trap when you only want to find a piece of text that happens to contain those characters.

Take a product line: price (USD): $4.99? Used as a pattern without escaping, it does not find itself. The brackets become a group, the $ asks for the end of the line in the middle of the text, the dot matches any character, and the ? makes the last 9 optional. Escaped, it becomes price \(USD\): \$4\.99\? with a backslash before each bracket, the dollar sign, the dot and the question mark. Every other character, letters, digits, the colon and the spaces, is already literal and is left alone. Paste the line into the box above and that is what comes back.

Escaping more than needed sounds safe but is not. Many engines accept a backslash before any punctuation, so \- or \: does no harm there. JavaScript is stricter: in a pattern with the u or v flag, an escape before a character that has no special meaning is a syntax error, so \- outside brackets breaks the whole pattern. The 14 syntax characters and the slash are the set that every common engine accepts escaped, which is why the tool escapes exactly those. Python's re.escape and Perl's quotemeta escape more, which is fine in those languages but not always when the pattern is copied somewhere else.

Match any line covers a common next step. Paste a list, such as a.b on one line and c+d on the next, and each line is escaped on its own and joined with a vertical bar: a\.b|c\+d. That pattern matches either line. If it is going inside a larger pattern, wrap it in a group, (?:a\.b|c\+d), so the bar does not split the rest of the pattern in two.

Two limits are worth knowing. First, this output is the pattern itself, not a string in your language. If you put it inside quotes in Java, C# or JavaScript, each backslash may need to be doubled, because the string reads backslashes before the regex engine does. Second, the escaping is for the main part of a pattern. Inside square brackets the rules are different: there ^ at the start, - between characters and ] are special, and a dot is just a dot. If you are building a character class by hand, escape those three yourself.

Frequently asked questions

Which characters does it escape?

The regex syntax characters ^ $ \ . * + ? ( ) [ ] { } | and the slash /. With the verbose option on, spaces and # as well.

Why is the hyphen not escaped?

Outside square brackets a hyphen has no special meaning, so it needs no escape. And escaping it can break the pattern: in JavaScript with the u or v flag, \- outside a character class is a syntax error.

Does the output work in Python, Java and other languages?

Yes. JavaScript, Python, PCRE (PHP and Perl), Java, Go and .NET all accept a backslash before each of these characters. In source code you may still need to double the backslashes, depending on how the language writes strings.

What is the verbose option for?

Verbose mode (the x flag, or re.VERBOSE in Python) ignores spaces in a pattern and treats # as the start of a comment. In that mode a literal space or # must be escaped too. Leave it off for ordinary patterns.

Is my text sent anywhere?

No. The escaping is one line of JavaScript running on this page.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.