Skip to content
Categories
Regex Escape
Escape a string for use in a regular expression.
Overview
- Escapes the string you enter so it can be treated as literal characters within a regular expression.
- Useful when you want to safely embed an arbitrary string, such as user input, as part of a regex pattern.
- Escapes characters that have special meaning in regular expressions — . * + ? ^ $ {} () | [] \ — with a backslash.
Usage
- Enter the string you want to escape into the text area.
- Click the "Escape" button.
- The result with regular expression special characters escaped is displayed. Use the "Copy" button to copy it to the clipboard.
Example
Input
hello.world
Output
hello\.world
Use Cases
- Safely embedding a user-entered search keyword into a regex pattern used for partial-match search
- Converting a string containing periods or symbols, such as a file path or price notation, so it's treated as a literal in a regex
- Safely escaping an arbitrary string that becomes part of a dynamically assembled regex pattern
FAQ
Which characters are escaped?
Characters that have special meaning in JavaScript regular expressions — . * + ? ^ $ { } ( ) | [ ] \ — are escaped.
Can I pass the escaped result directly to RegExp?
Yes. Using new RegExp(result) gives you a regular expression that matches the original string exactly.
Is the string I enter sent anywhere?
No. The escaping process happens entirely in your browser.
Notes
- Only characters with special meaning in JavaScript regular expressions — . * + ? ^ $ { } ( ) | [ ] \ — are escaped.
- Using new RegExp(result) on the escaped output gives you a regular expression that matches the original string exactly.
- Ordinary characters, such as Japanese text or emoji, are not converted and are output as-is.
Related Tools
Format HTML to make it easier to read.
Format CSS to make it easier to read.
Format JavaScript to make it easier to read.