Regex Escaper / Unescaper
Paste a string to escape all special regex characters (so it matches literally), or paste an escaped pattern to unescape it.
Reviewed by the ToolNestr Editorial Team — July 2026
How regex escaping works
Regex escaping prepends a backslash (\) before each special regex character to remove its metacharacter meaning. In regular expressions, characters like . (dot), * (star), and + (plus) have special meanings — dot matches any character, star means zero or more, plus means one or more. Escaping them turns them into literal characters.
The special characters that need escaping in JavaScript/PCRE regex are: . * + ? [ ] ( ) | ^ $ \. Each is prefixed with a backslash to match literally. For example, to match the string "hello.world" in a regex, it must be written as "hello\\.world" so the dot is treated as a literal period rather than the "any character" operator.
Worked example
Most escaped regex characters
Frequency of special characters in regex escaping scenarios.
Nina Petrov
Developer who builds search features and needs to escape user input before creating dynamic RegExp objects for accurate literal matching.
Ryan Mitchell
Data analyst who uses regex to clean and extract data from CSV files, often needing to escape column names that contain special characters like dots.
Fatima Al-Hassan
QA engineer who writes automated test assertions using regex patterns and needs to escape special characters in expected output strings.
Derek Johnson
Security researcher who analyzes log files with regex and needs to escape special characters in patterns to avoid false positives from regex metacharacters.
| Character | Escaped | Meaning in regex | Usage example |
|---|---|---|---|
| . | \. | Any character (except newline) | Match "foo.bar" literally |
| * | \* | Zero or more of preceding | Match "5*5" in a string |
| + | \+ | One or more of preceding | Match "C++" language name |
| ? | \? | Zero or one (optional) | Match "file?.txt" |
| [ | \[ | Start character class | Match array index "[0]" |
| ] | \] | End character class | Match closing bracket |
| ( | \( | Start capturing group | Match parentheses "(call)" |
| ) | \) | End capturing group | Match closing paren |
| \ | Start quantifier range | Match JSON braces | |
| \ | End quantifier range | Match closing brace | |
| | | \| | Alternation (OR) | Match pipe "A|B" |
| ^ | \^ | Start of string / negation | Match caret "^caret" |
| $ | \$ | End of string | Match dollar "$price" |
| \ | \\ | Escape character | Match backslash |
How to use Regex Escaper
Paste your input
Type or paste a string that contains special regex characters, or an already-escaped pattern you want to unescape.
Escape or unescape
Click Escape to add backslashes before special characters. Click Unescape to remove backslashes from an escaped pattern.
Use in your code
Copy the escaped string for use with new RegExp(), or the unescaped string for display or further processing.
Tips for regex escaping
Always escape user input
When using user-provided strings with new RegExp(), always escape the string first. Unescaped user input in regex creates both functional bugs and potential ReDoS (Regular Expression Denial of Service) vulnerabilities.
Test your escaped patterns
After escaping, test the pattern against your expected input to verify it matches correctly. The analysis section shows which characters were escaped, helping you confirm the output is correct.
Consider using alternative APIs
In modern JavaScript, consider using String.prototype.includes(), startsWith(), or endsWith() for simple literal matching instead of regex. They are faster and avoid escaping entirely. Save regex for patterns that need its power.
What is a regex escape?
A regex escape is the process of prefixing a special character with a backslash to remove its metacharacter meaning and treat it as a literal. For example, the dot (.) normally matches any single character, but escaping it as \. makes it match only an actual dot character. Escaping is essential when building regex patterns from strings that should be matched exactly.
Why escaping matters
Without escaping, special regex characters will be interpreted as operators rather than literals. For example, if you search for "example.com" without escaping, the dot matches any character, so the pattern would also match "exampleXcom". Escaping ensures that your regex matches exactly what you intend, preventing subtle bugs and security issues.
Special characters list
The special characters in regex are: . (dot) matches any character, * (star) matches zero or more, + (plus) matches one or more, ? (question) makes preceding optional, [ ] define character classes, ( ) create groups, specify quantifiers, | is alternation (OR), ^ asserts start, $ asserts end, and \ is the escape character itself. Each must be escaped with a backslash to match literally.
When to escape / unescape
Escape when building regex from dynamic strings, user input, or any string that might contain metacharacters where you want literal matching. Unescape when displaying a regex pattern to users, when porting patterns between languages, or when you need to inspect the original literal content. Use this tool to quickly switch between both forms.
Frequently asked questions
What does it mean to "escape" a regex character?
Escaping a regex character means prefixing it with a backslash to tell the regex engine to treat it as a literal character instead of a special operator. For example, \. matches a literal dot instead of "any character."
Which characters are special in regex?
The special regex characters are: . * + ? [ ] ( ) { } | ^ $ \. Each has a specific meaning in regex patterns, and they must be escaped to match literally.
When should I escape a regex pattern?
Escape when you are building a regex from user input or dynamic strings that should be matched literally. For example, if a user searches for "foo.bar", you should escape it so it matches "foo.bar" literally instead of "foo-bar" or "fooXbar".
When should I unescape a regex pattern?
Unescape when you receive an already-escaped pattern and want to inspect, modify, or display it in human-readable form. Removing the backslashes reveals the original literal string.
Does escaping affect regex performance?
No significant impact. An escaped character is treated as a literal, which the regex engine can match very quickly. Escaping is about correctness, not performance.
Can I escape a string for use with new RegExp()?
Yes. That is the most common use case. Take a dynamic string, escape all special characters with this tool, then pass the escaped string to new RegExp(escapedString) to create a pattern that matches the input literally.
What happens if I escape an already-escaped string?
Characters that already have a backslash prefix will get an additional backslash. For example, \. becomes \\. This double escaping is rarely intended, so only escape strings that are not already escaped.
Is regex escaping the same in all languages?
The set of special characters is similar across languages (PCRE, JavaScript, Python, Java, etc.), but there are minor differences. This tool follows the JavaScript/PCRE convention for the special characters.
Why is the backslash character itself special?
The backslash is the escape character in regex. It is used to escape other special characters and to create special sequences like \d (digit), \w (word char), and \s (whitespace). To match a literal backslash, you must write \\.
How do I match text that contains special characters?
Use this tool to escape the entire text, then use the escaped version in your regex. Alternatively, you can wrap individual special characters in brackets ([.]) to make them literal, but escaping is cleaner for longer strings.