JS Regex Escaper — Free Online Tool

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.

More JavaScript Tools

Template Literal → Concat
Convert ES6 template literals with ${expr} interpolation into equivalent string concatenation, string and regex aware
Ternary to If/Else
Expand ternary assignments, declarations and returns into readable if/else blocks, safely skipping ?? and ?. operators
List to JS Array
Turn a list of lines, comma or space separated values into a JavaScript array literal with quoting, trimming and de-duplication
JS Variable Name Validator
Check whether a name is a valid JavaScript identifier and explain each problem — digits, symbols, spaces or reserved keywords
JS Quote Normalizer
Convert JavaScript string quotes between single and double, string, comment and regex aware, re-escaping quotes as needed
JSON Key Sorter
Recursively sort the keys of a JSON object alphabetically (ascending or descending) with configurable indentation

← View all JavaScript Tools