String Escape / Unescape
Escape or unescape strings for JavaScript, Java, or regex, each handling its own special characters.
How this tool works
Choose a language context
JavaScript, Java, or Regex - each escapes a different set of characters.
Choose escape or unescape
Escape turns raw text into a safely embeddable literal; unescape reverses it.
Paste your text
Raw text to escape, or already-escaped text to convert back.
Copy the result
Ready to paste directly into source code or a regex pattern.
Quick facts
- Category
- Encoders & Decoders
- Best for
- Safely embedding a literal value inside a regex pattern or a JS/Java string literal
About this tool
Switch between three modes - JavaScript string, Java string, and regex - and escape or unescape text for that specific context, since each one treats "special" characters differently. JavaScript and Java modes both handle backslashes, quotes, and whitespace control characters (\n, \t, \r, \f, \b) plus \uXXXX unicode escapes, with JavaScript additionally recognizing the \xXX hex escape that Java string literals don't support. Regex mode is a different job entirely - it escapes the characters that have special meaning inside a regular expression pattern (. * + ? ^ $ { } ( ) | [ ] \ /), so a literal value containing those characters (like a price with a decimal point, or a URL) can be safely dropped into a regex pattern without its literal characters being misread as metacharacters. Runs entirely client-side.
Why use this tool
Three distinct contexts, not one generic mode
JavaScript, Java, and regex each escape a genuinely different set of characters.
Handles unicode and hex escapes
\uXXXX unicode escapes in both modes, plus \xXX hex escapes where JavaScript actually supports them.
Regex-safe escaping included
Escapes regex metacharacters specifically, so a literal string can be dropped into a pattern safely.
Swap to reverse direction
Feed the output back in as new input and flip escape/unescape with one click.
Frequently asked questions
Both escape backslashes, quotes, and the common whitespace control characters (\n, \t, \r, \f, \b) the same way, and both support \uXXXX unicode escapes. The one difference this tool implements is the \xXX hex escape, which JavaScript string literals support but Java string literals do not - Java mode won't decode a \x sequence as a hex escape, matching how a real Java compiler would treat it.
Regular expressions treat characters like ".", "*", "+", "(", and "[" as metacharacters with special meaning, so dropping a literal string containing them - a price like "$19.99", a file path, a URL - directly into a regex pattern would misinterpret those characters instead of matching them literally. Regex-escaping adds a backslash in front of each metacharacter so the pattern matches the literal text exactly.
Unrecognized escape sequences fall back to just the character after the backslash, with the backslash itself dropped - the same behavior both JavaScript and Java use for an escape sequence that isn't one of the defined special cases. This means unescaping is forgiving of unusual input rather than failing outright on it.
Explore more free tools
Formatters, converters, validators, and generators - all free and running entirely in your browser.
Browse more tools