Regex Escape
Escape special regex characters in a string for literal matching.
Last updated: August 2026
Characters escaped: . * + ? ^ $ { } ( ) | [ ] \
Was this tool helpful?
Why you escape characters in a regex
Regular expressions treat many punctuation characters as operators rather than literal text. A dot matches any character, a plus means "one or more", and parentheses create a group. When you want to match those characters literally, you escape them with a backslash so the engine reads \. as a real period instead of "any character". Escaping is what you do when the input is data, not a pattern you wrote by hand.
The characters that need escaping
The usual suspects are . * + ? ^ $ ( ) [ ] { } | \and the forward slash when it is your delimiter. Each has a special meaning on its own, so a stray one silently changes what your pattern matches. The safe move when you build a pattern from user input is to escape every one of these before inserting the string, which prevents both broken matches and a form of injection where input alters the regex logic.
Example
A URL contains several regex-special characters:
Input: https://a.com/path?id=1
Escaped: https://a\.com/path\?id=1Only the dot and the question mark needed escaping to match literally.
FAQ
Does everything need a backslash? No. Letters, digits, and most spaces are already literal. Over-escaping harmless characters makes the pattern unreadable without changing behavior.
Is escaping different inside a character class? Yes. Inside [ ] most metacharacters lose their power, so you escape fewer things, but the dash and the caret still need care.
Is there a built-in escape function? Many languages ship one, such as re.escape in Python. JavaScript has no native helper, so a small escape routine or a tool like this one fills the gap.