Java string escape / unescape
Paste text to get a valid Java string literal, paste a literal to see the real text, or build a text block.
Escaping without the guesswork
Pasting JSON, SQL, regex or a file path into Java source means escaping every backslash and quote. Miss one and the code does not compile, or worse, compiles to something different. The unescape direction helps when you copy a literal out of a stack trace or a log and want to read the real text.
For regular expressions, the regex tester prints the pattern as a ready-to-paste Java string.
Frequently asked questions
What needs escaping in a Java string?
The backslash (\\), the double quote (\") and control characters such as newline (\n), tab (\t) and carriage return (\r). Anything outside ASCII can be written as \uXXXX.
What is a text block?
Since Java 15 a multi-line string can be written between """ delimiters without escaping newlines or quotes. Indentation is stripped based on the closing delimiter.
Why does Java reject my escape?
Java allows only a fixed set: \b \t \n \f \r \s \" \' \\, octal and \uXXXX. Anything else, like \d in a regex, must be written \\d.
What about emoji?
Characters above U+FFFF are written as a surrogate pair of two \u escapes, which this tool does for you.