Escape a literal string so its special characters are matched literally inside a RegExp, with optional forward-slash escaping. JS Regex Escaper is a free online tool from the ToolsRift JavaScript Tools collection. It runs entirely in your browser — nothing to install, no signup, and your data never leaves your device.
Loading JS Regex Escaper…
How to use JS Regex Escaper
Paste the literal text you want to match, optionally enable slash escaping for regex literals, then copy the escaped output to drop into new RegExp().
Frequently asked questions
Which characters are escaped?
The regex metacharacters . * + ? ^ $ { } ( ) | [ ] and backslash are prefixed with a backslash so they are treated as literal text rather than pattern operators.
When do I need slash escaping?
Only when building an inline /pattern/ literal. Enable it to also escape forward slashes. For new RegExp('...') you usually do not need it.
Is this the same as MDN's escape function?
Yes. It uses the well-known pattern str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') recommended in the MDN RegExp guide.
ToolsRift processes your files in your browser. We use cookies only for basic analytics and to support ads that keep every tool free. See our Cookie Policy.