Loading…

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
var to let / const
Replace the var keyword with let or const across your code, string, comment and regex aware so text like \
JavaScript Formatter
Beautify and format JavaScript code with proper indentation and structure for better readability
JavaScript Minifier
Minify JavaScript by removing whitespace, comments, and shortening variable names to reduce file size
JavaScript Validator
Validate JavaScript syntax and find errors with detailed line numbers and error messages
JSON to JS Object
Convert JSON data to JavaScript object literal syntax with proper formatting and structure
JS Object to JSON
Convert JavaScript object literals to valid JSON format with proper escaping and structure

← View all JavaScript ToolsBrowse all 1,100+ tools →