String Escape & Unescape

Turn raw text into a correctly escaped string literal for your language, or unescape a literal back to plain text.

Loading tool…

About the String Escape

Every language has its own rules for string literals. JSON requires \", \\ and \n-style escapes and \u00XX for other control characters. JavaScript also escapes ' and backticks and uses \x for control characters plus \u2028/\u2029, which break older engines. Java/C# use \uXXXX; Python uses \xHH and understands \U0010FFFF and octal on unescape.

SQL string literals escape a single quote by doubling it: O'Reilly → O''Reilly. That is handy for scripts and fixtures, but in application code always use parameterised queries instead of building SQL strings. CSV quotes a field that contains a comma, quote, line break or leading/trailing space, and doubles embedded quotes (RFC 4180). Regex escapes the metacharacters . * + ? ^ $ { } ( ) | [ ] \ / so a string matches literally.

Unescaping reports invalid sequences with their position, such as a lone trailing backslash or a \u without four hex digits. Everything runs locally.

How to use it

  1. Choose Escape or Unescape.
  2. Select the target language or format.
  3. Paste the text or literal (without the surrounding quotes).
  4. Copy the output into your code.

Frequently asked questions

Should I include the surrounding quotes?
No. Paste only the content between the quotes. The CSV mode is the exception: it adds the quotes when a field needs them.
Is doubling single quotes enough to prevent SQL injection?
It handles standard SQL string literals, but encoding settings and backslash modes (MySQL) can create edge cases. Use prepared statements with bound parameters in real code.
How do I escape a string for use in a RegExp?
Choose Regular expression. In JavaScript you can use the result in new RegExp(escaped) to match the text literally.
What is the difference between JSON and JavaScript escaping?
JSON strings are always double-quoted and allow a fixed set of escapes. JavaScript additionally allows \x, \u{…}, \v, \0 and single-quoted or template strings.

Related tools