Category: Developer tools
Regex Escape Tool
Escape text for literal use inside a regular expression
Escape every regular-expression metacharacter in a block of text so it can be matched literally, then copy the result as a JavaScript regex literal or a RegExp constructor call. Runs entirely in your browser.
Prices start at \$4\.99 \(per item\)\? \[ask sales\]
/Prices start at \$4\.99 \(per item\)\? \[ask sales\]/g
new RegExp("Prices start at \\$4\\.99 \\(per item\\)\\? \\[ask sales\\]", "g")Everything on this page is processed in your browser. Nothing is uploaded.
What this tool does
Building a pattern that matches a literal string such as a price, a file path or a URL fails as soon as the text contains a character regex treats specially, like a dot, a parenthesis or a question mark. This tool escapes every metacharacter the JavaScript regex engine recognises and renders the result two ways: as a `/pattern/flags` literal and as a `new RegExp(...)` call, so either fits straight into your code.
How to use it
- Paste the literal text you want to match.
- Set the flags you want on the generated pattern, such as g or i.
- Copy the escaped text, the literal form or the constructor call.
Privacy
This tool runs entirely in your browser. Your input is never uploaded, stored or shared — closing the tab removes it.
Frequently asked questions
- Is my text uploaded anywhere?
- No. Escaping happens in JavaScript running in the page, so nothing you paste ever leaves your device.
- Which characters get escaped?
- Every character the JavaScript regex engine treats specially: . * + ? ^ $ { } ( ) | [ ] \ and /, so the escaped text always matches itself literally.
- Why are there two code samples?
- A literal (/.../) is the usual way to write a fixed pattern, but it cannot be built from a variable at runtime; the RegExp constructor form can, which matters if the text is not always this exact value.