Skip to content
1001 Tools
sr
Developer tools

Regex Escape

Paste any text and get a version safe to drop into a regular expression, with every special character backslash-escaped. This is what you need when a search term contains dots, brackets, or other symbols that would otherwise be interpreted as regex syntax. It runs entirely in your browser.

Escaped for regex

How it works

A regular expression treats characters like . * + ? ^ $ { } ( ) | [ ] and the backslash as syntax rather than literal text. This tool puts a backslash in front of each of those, so the pattern matches them exactly. For example the input “a.b” becomes “a\.b”, which matches the literal string “a.b” instead of “a” followed by any character followed by “b”.

The escaped set matches the standard used across JavaScript, and the result is safe to build patterns from with new RegExp(). It escapes only what must be escaped to be matched literally in the main body of a pattern — it does not wrap the text in delimiters, add flags, or handle character-class-specific rules, so you paste the output straight into wherever you are assembling your regex.

Practical examples

Searching for a price

To match the literal text “$9.99 (USD)” you need “\$9\.99 \(USD\)”. Paste the price and copy the escaped version so the dollar sign, dot and parentheses are treated as text.

Building a pattern from user input

When a search box feeds a regex, unescaped input like “C++” can throw an error or match wrongly. Escaping it to “C\+\+” makes the search safe and literal.

Matching a file path

A Windows path such as “C:\Users\a.txt” is full of backslashes and a dot. Escaped, it becomes a pattern that matches the path exactly.

Frequently asked questions

Which characters get escaped?

The regex metacharacters: . * + ? ^ $ { } ( ) | [ ] and the backslash itself. Every other character, including letters, digits and spaces, is left unchanged.

Why do I need to escape text for a regex?

Because symbols like . and * mean “any character” and “repeat” in a pattern. If your search term contains them and you want them treated literally, they must be escaped or the regex will match the wrong things — or fail to compile.

Is the output safe to use with new RegExp()?

Yes. The escaped string can be passed directly into new RegExp() or concatenated into a larger pattern, and it will match your original text literally.

Does it add slashes or flags like /…/g?

No. It only escapes the characters. You add the delimiters and any flags yourself, which keeps the output flexible for use in code or in a search field.

Does it handle character classes correctly?

The output is intended for the main body of a pattern. Inside a character class ([…]) the rules differ slightly — for instance the hyphen and caret can be special — so review the result if you are pasting into a class.

Is this the same as encoding or URL-escaping?

No. This is specifically regex escaping. URL encoding and HTML entity encoding solve different problems; use the URL encoder or HTML entities tool for those.

What about escaping the forward slash?

The forward slash is not a metacharacter in the pattern body, so it is not escaped. You only need to escape it when it would clash with /…/ literal delimiters, which you control yourself.

Can I escape multiple lines at once?

Yes. Paste as much text as you like; every line is processed and newlines are preserved, so you can escape a whole block in one go.

Is my text uploaded anywhere?

No. Escaping happens entirely in your browser with JavaScript. Nothing is sent to a server, and it works offline once the page has loaded.

Related tools