Regex Escape Tool
Escape special regex characters so a string can be used as a literal pattern.
Output updated — 26 characters
Escape Tester Playground
Live Highlighted Matches2 matches found
We have Hello (World) + $5.00 ready, and also another Hello (World) + $5.00 here!
Special characters escaped
.*+?^${}|[]()\\
Why escape regex characters?
Regex metacharacters like . * + ? ^ $ { } | [ ] ( ) \ have special meaning in a regular expression. If you want to match them literally — for example, matching the price string $5.00 — they must be escaped with a backslash.
Use the Escape Tester Playground to verify your escaped pattern against target testing strings in real-time. Toggle flags such as Global (g) and Ignore Case (i)to observe matches highlighted on-the-fly. This tool works with standard regex rules for JavaScript, Python, Java, PHP, and Rust.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Escaping a literal string so it can be used inside a pattern safely.
- Building a pattern from user input without it being interpreted.
- Escaping a file path or a URL for a regex match.
- Checking which characters in a string actually need escaping.
- Producing an escaped literal for a script.
Frequently Asked Questions
- Which characters need escaping?
- The twelve that carry meaning in a pattern: `. * + ? ^ $ { } | ( ) [ ] \`. Everything else is literal already. The commonest one to forget is the dot, which matches any character — so an unescaped `example.com` also matches `exampleXcom`.
- Why escape at all if I control the string?
- Because you usually do not. Any pattern built from user input, a filename or a database value can contain a metacharacter, which either changes what the pattern matches or throws a syntax error. Building a regex from unescaped input is the regex equivalent of SQL injection.
- Is there a built-in escape function in JavaScript?
- No. A `RegExp.escape` proposal has been through the standards process for years, so every codebase carries its own `replace(/[.*+?^${}()|[\]\\]/g, '\\$&')` one-liner. That expression is exactly what this tool applies.
- Do I need to escape a forward slash?
- Only inside a regex literal, where `/` would terminate the pattern early. Passing the same pattern as a string to `new RegExp()` needs no slash escaping at all — which is why a pattern copied from a literal into a string often has a stray backslash in it.
- What about characters inside a character class?
- The rules change: inside `[...]` only `^` (when first), `]`, `-` and `\` are special, and the twelve outside metacharacters mostly become literal. Escaping all of them anyway is harmless and simpler than remembering two rule sets.
Common errors and gotchas
- Escaping for the wrong flavour, since the metacharacter set differs between engines.
- Forgetting the escaping needs doing again for the host language's string literal.
- Over-escaping, which in some engines turns a harmless character into an error.
- Escaping the replacement string as if it were a pattern, where the rules differ.
- Building a pattern from unescaped user input, which is a denial-of-service route as well as a bug.
Related Developer Utilities tools
RegExp Tester
Test regular expressions and inspect matches locally.
Regex Visualizer
Visual regex pattern diagram with live match highlighting and capture group annotations.
Subnet Calculator
Compute CIDR subnets, usable hosts, and network ranges.
Cron Parser
Translate cron syntax into plain English.
URL Parser
Break a URL into protocol, host, path, and query parts.
HTML Previewer
Paste HTML and see it rendered live in a safe, sandboxed preview.
HTTP Status Code Reference
Search and look up every HTTP status code and its meaning.
MIME Type Lookup
Find the MIME type for a file extension, or the extensions for a MIME type.