String Escape Tool

Escape a string for use as a JS/JSON string literal or a regex pattern.

Every calculation runs locally in your browser. Nothing you enter here is sent anywhere.

For informational and educational purposes only — not professional or technical advice, and not a substitute for consulting a qualified professional about your specific situation. TrueMeasureKit is not liable for decisions made based on these results. See our Terms of Service.

Two different kinds of "special" characters

A string literal and a regex pattern treat entirely different characters as special. Quotes, backslashes, and control characters like newlines need escaping to sit safely inside a quoted string — that's what the string-literal output handles. A regex pattern instead needs characters like . * + ? ^ $ { } ( ) | [ ] escaped so they match themselves literally instead of being interpreted as pattern syntax — useful when building a regex out of user-supplied or otherwise arbitrary text.

Frequently asked questions

Why does a string need different escaping for JSON versus a regex pattern?

Each format has its own set of special characters — JSON requires escaping quotes and backslashes for a valid string literal, while regex requires escaping characters with special pattern meaning like . * + ? ( ) — using the wrong escaping for the context breaks the result.

Advertisement
Adaptive banner

We use cookies for analytics and to show ads, including personalized ads from Google. You can accept or reject these — the calculators themselves never send your inputs anywhere either way. See our Privacy Policy for details.