What does escaping a regex mean?
Escaping a regular expression means adding backslashes before characters that would otherwise act as instructions, so they're matched as ordinary text. It's needed whenever user input, file names, prices or URLs go into a pattern, and forgetting it causes subtle bugs and even security issues.
Paste your text and choose whether it's for a pattern, a JavaScript literal or a replacement string. Optionally escape each line separately and join them with |. The escaped result is ready to copy, with a count of how many characters were escaped.
How to use the Regex escape
1.Paste the text
Exactly what you want to match.
2.Choose where it goes
A pattern, a /…/ literal or a replacement string.
3.Copy the pattern
Paste it into your code or search box.
Example: matching a price label
Matching the exact text "Price: $19.99 (incl. tax) [sale?]":
- Escaped
- Price: \$19\.99 \(incl\. tax\) \[sale\?\]
- Characters escaped
- 8
The pattern now matches only that exact label, not lookalikes such as Price: X19a99.
Characters that need escaping
Twelve characters have special meaning in regular expressions: . * + ? ^ $ { } ( ) | [ ] and the backslash itself. Each gets a backslash in front, so $19.99 becomes \$19\.99 and matches the price instead of 'end of line, then 19, any character, 99'.
Inside a JavaScript /…/ literal the forward slash also needs escaping. In replacement strings only $ is special, written $$. Escaping a list one line at a time and joining with | builds a pattern that matches any of several words or phrases, such as a list of product names to find in a log.
Frequently asked questions
Does this work outside JavaScript?
Yes. The same escapes work in Python, Java, PHP, Go, .NET and most editors.
Is escaping a hyphen needed?
Only inside [ ] character classes; elsewhere a hyphen is literal.
How do I match any of several words?
Put one per line and tick Each line separately.
Is my text stored?
No. Nothing is kept.
Related tools
Regex Tester
Test JavaScript regular expressions with live highlighting, groups and replace.
Regex match extractor
List every regex match or capture group in text, as lines or CSV.
Split text by regex
Split text at any pattern, like mixed commas, semicolons and pipes.
Text Diff Checker
Compare two texts by line, word or character and see what changed.
Cron Expression Explainer
Translate a cron schedule into plain English and see its next run times.
Lorem Ipsum Generator
Placeholder text by paragraph, sentence or word, plain or in <p> tags.
More Developer tools
JSON & data
CSV tools
Network & system
Web & API
Git & releases
Encoding & security
- Base64 encode & decode
- URL encode & decode
- JWT decoder
- Hash generator
- HTML entity encoder
- Text to binary
- Morse code translator
- Caesar cipher & ROT13
- Random string generator
- Secret key generator
- 2FA code generator (TOTP)
- Encrypt & decrypt text
- Encrypt & decrypt files
- SSH key generator
- Base32 encoder and decoder
- Unicode escape converter
- Nano ID generator
- JWT generator