Regex Escape Tool
Escape every regex metacharacter in a string so it matches literally inside a pattern.
Every regex metacharacter has a job: the dot matches anything, the plus means "one or more", brackets open character classes. When you want to match a literal price.total or file[v1], those characters fight back. Escaping them - prefixing each with a backslash - tells the engine to treat them as plain text. This tool does that for you in one click.
Paste any string and press Escape. Every metacharacter - . * + ? ^ $ { } ( ) | [ ] and the backslash itself - is prefixed with a backslash, so the output can be dropped directly into a regular expression and match the original text exactly.
The reverse need is just as common: you have a pattern and want to know which characters it treats specially. The same escaping works for turning a user-supplied value into a safe literal in code that builds regexes on the fly - for example a search box whose terms should not become wildcards. Everything runs locally; your string never leaves the browser.
Features
- Escapes every regex metacharacter, including the backslash itself.
- Output drops straight into any regex pattern as a literal match.
- Leaves non-special characters untouched, keeping the output readable.
- Perfect for search boxes and filters that must match user input literally.
- One-click copy of the escaped result.
- Fully offline - no uploads, no logs.
How to Use
- 1
Paste the string
Enter the literal text you want to make regex-safe, such as a file name, a search term or a code fragment.
- 2
Escape
Press Escape. Every metacharacter gets a backslash prefix, and everything else stays as-is.
- 3
Use the result
Paste the escaped string where a pattern is expected - inside a new RegExp(...), a regex literal, or a match operation.
- 4
Verify
Test the escaped pattern against your input to confirm it matches exactly what you intended.
Example
File name with dots and brackets
report[v1].final↓
report\[v1\]\.finalQuery fragment
a+b*c?↓
a\+b\*c\?Common Problems
Escaping only some characters
A hand escape that covers the dot but misses the plus or the question mark still matches the wrong thing. Escaping the full set in one pass is what makes a string genuinely literal.
Double-escaping
Escaping an already-escaped string adds another backslash, so \d becomes \\d and matches a backslash instead of a digit. Escape exactly once, at the point where the user input enters the pattern.
Forgetting the backslash itself
The backslash is the escape character, so a literal backslash in user input needs escaping too. The tool handles it; a hand-written list often forgets it.
Escaping inside a character class
Inside [ ... ] the escaping rules differ - a minus or a caret changes meaning, while a dot does not. This tool escapes for a normal pattern context; build classes separately with care.
Treating escaping as validation
Escaping only makes text match literally. It does not validate, sanitize or secure anything - a string can be safely matched while still containing whatever it contains.
Escaping the wrong side of a comparison
Escape the dynamic value, not the fixed pattern. If you build a matcher from user input, escape that input; the fixed pattern you wrote by hand should stay as-is.
Escaping with the wrong escape set
Different regex flavors add special characters - the # comment marker, the / delimiter - that are not in the core metacharacter set. This tool escapes the JavaScript core set; check your target flavor for extras.
Confusing escape for newline
A literal backslash-n in your input is a backslash followed by an n, and escaping produces \\n - which in a pattern is the newline class, not a literal slash-n. If you meant an actual newline character, paste the real line break instead.
Technical Details
The escape set is the canonical JavaScript metacharacter list: . * + ? ^ $ { } ( ) | [ ] and \. Each is prefixed with a backslash, so the dot becomes \. and the backslash becomes \\.
Characters that have no special meaning - letters, digits, spaces, dashes - pass through unchanged, so the escaped output stays readable and minimal.
The tool operates on the string as plain text, not through the regex engine, so it is safe even when the input contains sequences that would otherwise be parsed as escapes.
The tool escapes one level deep: it treats the input as already-final text. An input containing a literal backslash becomes a double backslash, which is the correct representation for matching that backslash literally.
Escape output is intended for use inside a pattern body, not inside a character class or as a replacement string - those contexts have their own additional escaping rules.
Processing is local and synchronous. The string is transformed in your browser and never transmitted.
Frequently Asked Questions
Why would I escape a string?
When you build a regex from a value that should match literally - a user's search term, a file name, an ID - unescaped metacharacters in that value act as pattern syntax and change the match. Escaping neutralizes them.
What characters count as special?
The metacharacters with meaning outside a character class: . * + ? ^ $ { } ( ) | [ ] and the backslash. This tool escapes exactly that set and leaves everything else alone.
Does escaping a string twice cause problems?
Yes. Each pass prefixes another backslash, so the result no longer matches the original text. Escape once, at the boundary where untrusted input enters the pattern.
Is my input uploaded?
No. Escaping happens entirely in your browser. The string is processed in memory and never transmitted, stored or logged.
Can I use this with languages other than JavaScript?
Mostly, yes - the metacharacter set is shared across PCRE-style engines in JavaScript, Python, Ruby and many others. Backslash escaping works the same way in all of them.
Does escaping make my pattern "safer"?
It makes it literal, which prevents accidental wildcard behavior. It is not a security mechanism on its own - validate inputs for their actual purpose, and use escaping only to control matching.
Data & Privacy
Your data stays in your browser. Nothing is uploaded.
- Processing
- Local
- Upload
- None
- Server Storage
- None
- Account
- Not required
Related Tools
Regex Tester
Test regex patterns against your text with live highlighting, capture groups and common-pattern shortcuts.
Regex & Text
Regex Builder
Compose regular expressions from reusable blocks and watch matches highlight live against your test text.
Regex & Text
Text Diff Checker
Line-by-line text comparison that shows every added, removed and unchanged line.
Regex & Text
JSON Formatter
Format, validate and beautify JSON directly in your browser.
JSON & Data
HTML Entity Encoder / Decoder
Convert HTML to its escaped entity form or decode entities back to readable markup.
Encoding & Conversion
URL Encoder / Decoder
Percent-encode text for safe use in URLs and query strings, or decode it back to readable form.
Encoding & Conversion
Related Guides
Regular Expressions Guide: How Regex Works with Examples
Learn regular expressions from scratch: literals, metacharacters, character classes, quantifiers, anchors, groups and flags, with examples you can test online.
Regex Cheat Sheet: Every Metacharacter Explained
A compact regex cheat sheet: anchors, character classes, quantifiers, groups, alternation and flags, with the meaning and an example for every common token.
Email Regex: How to Validate an Email Address
A practical email regex, why the full RFC 5322 pattern is a trap, and how to validate email in HTML5, JavaScript and Python without over-engineering.
URL Regex: How to Match and Validate a URL
Match and validate URLs with regex: protocol, host, path, query and fragment, plus practical patterns and when to use the URL API instead of a regex.