ToolNestr

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

Input: "hello.world[test]"
Escaped: "hello\\.world\\[test\\]" (escaping . [ ])

Most escaped regex characters

Frequency of special characters in regex escaping scenarios.

. (dot)25% of escapes
* (star)20%
+ (plus)15%
? (question)12%
[ ] (brackets)10%
( ) | ^ $ \18%
👩‍💻

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.

CharacterEscapedMeaning in regexUsage example
.\.Any character (except newline)Match "foo.bar" literally
*\*Zero or more of precedingMatch "5*5" in a string
+\+One or more of precedingMatch "C++" language name
?\?Zero or one (optional)Match "file?.txt"
[\[Start character classMatch array index "[0]"
]\]End character classMatch closing bracket
(\(Start capturing groupMatch parentheses "(call)"
)\)End capturing groupMatch closing paren
\Start quantifier rangeMatch JSON braces
\
End quantifier rangeMatch closing brace
|\|Alternation (OR)Match pipe "A|B"
^\^Start of string / negationMatch caret "^caret"
$\$End of stringMatch dollar "$price"
\\\Escape characterMatch backslash

How to use Regex Escaper

1

Paste your input

Type or paste a string that contains special regex characters, or an already-escaped pattern you want to unescape.

2

Escape or unescape

Click Escape to add backslashes before special characters. Click Unescape to remove backslashes from an escaped pattern.

3

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.

All tool categories

Converters (69 tools)
📊 CSV ↔ JSON Converter📄 JSON ↔ YAML Converter🔀 JSON ↔ XML Converter💿 Text ↔ Binary Converter🔢 Text ↔ Hex Converter🔗 URL Encoder / Decoder🏷️ HTML Entity Converter📡 Morse Code Converter💻 ASCII Code Converter🔤 Regex Escaper / Unescaper📄 GSM to mm Calculator💾 Data Storage Converter📡 Data Transfer Rate Converter⛽ Fuel Economy Converter📏 Feet & Inches Calculator📐 Inches to Fraction Calculator⚖️ Kg to Lbs Converter⚖️ Lbs to Kg Converter⚖️ Kg to Stone Converter⚖️ Stone to Kg Converter⚖️ Grams to Ounces Converter⚖️ Ounces to Grams Converter⚖️ Grams to Pounds Converter⚖️ Pounds to Grams Converter⚖️ Mg to Grams Converter⚖️ Metric Tons to Kg Converter📏 Cm to Inches Converter📏 Inches to Cm Converter📏 Cm to Feet Converter📏 Feet to Cm Converter📏 Mm to Inches Converter📏 Inches to Mm Converter📏 Meters to Feet Converter📏 Feet to Meters Converter📏 Km to Miles Converter📏 Miles to Km Converter📏 Yards to Meters Converter📏 Feet to Inches Converter📏 Inches to Feet Converter📏 Nautical Miles to Km Converter🌡️ Celsius to Fahrenheit Converter🌡️ Fahrenheit to Celsius Converter🌡️ Celsius to Kelvin Converter🌡️ Kelvin to Celsius Converter🧪 Liters to Gallons (US) Converter🧪 Gallons (US) to Liters Converter🧪 Ml to Fluid Ounces (US) Converter🧪 Fluid Ounces to Ml Converter🧪 Cups (US) to Ml Converter🧪 Quarts to Liters Converter🏎️ Mph to Km/h Converter🏎️ Km/h to Mph Converter🏎️ Knots to Mph Converter🔧 Psi to Bar Converter🔧 Bar to Psi Converter📏 Length Converter⚖️ Weight Converter📐 Area Converter🧪 Volume Converter🏎️ Speed Converter🔧 Pressure Converter⚡ Energy Converter🔌 Power Converter📐 Angle Converter🔢 Number to Words Converter🔢 Words to Numbers Converter➗ Decimal to Fraction Converter➗ Fraction to Decimal Converter🔬 Scientific Notation Converter
🌐 Networking & IP Tools (36 tools)
🧮 Everyday (26 tools)
💪 Health & Fitness (30 tools)
💰 Finance (34 tools)
🔢 Math (23 tools)
📄 PDF Tools (10 tools)
🎨 Creators (12 tools)
💻 Developers (24 tools)
⚡ Engineering & Science (24 tools)
⚛️ Physics (48 tools)
🧪 Chemistry (50 tools)
🧬 Biology (50 tools)
🏠 Construction & Home Improvement (105 tools)
👗 Clothing & Garment Tools (68 tools)
🍳 Cooking & Baking (9 tools)
🚗 Automotive (26 tools)
🖼️ Image Tools (13 tools)
🔐 Security & Hash (15 tools)
📝 Text Tools (15 tools)
🔍 SEO Tools (11 tools)
🕐 Time & Date (15 tools)
📊 Chart Generators (11 tools)
🕌 Islamic Tools (16 tools)