String Escape & Unescape

Make text safe to put inside a string literal in JavaScript, Java, Python, SQL, a regular expression or HTML, or reverse it.

Why escape strings?

Quotes, backslashes and line breaks have special meaning in code. Escaping adds the right backslashes or entities so the text is read literally.

Choose the context

Select JavaScript, Java, Python, SQL, Regex or HTML, then Escape or Unescape. Rules differ between languages, so pick the one you are writing in. Unescape is simple find-and-replace, run one sequence after another, so a doubled backslash before a letter (an escaped Windows path such as C:\\new\\table) can be misread as a line break or tab. Check unescaped paths by eye.

How to use it

  1. Pick the Language / context.
  2. Paste text into Input.
  3. Press Escape or Unescape and copy the output.

JavaScript example

The text with quotes and a line break:

He said "hi"
New line	tab

is escaped to: He said \"hi\"\nNew line\ttab

Common use cases

What each mode escapes

The result depends entirely on the mode you pick, and the rules are deliberately simple:

Worked example

The input below has quotes, an ampersand, a Windows path, a line break and a tab:

He said "hi" & it's C:\temp
line2<TAB>tab

In JavaScript mode, Escape produces:

He said \"hi\" & it\'s C:\\temp\nline2\ttab

The same input in SQL mode only changes the apostrophe (it''s), and in HTML mode becomes He said &quot;hi&quot; &amp; it&#39;s …. Regex mode would leave this input almost untouched because none of its characters are regex operators. A literal price such as $5.00 (approx) becomes \$5\.00 \(approx\).

Unescape is simpler than it looks

Unescape in JavaScript, Java and Python mode replaces \n, \r, \t, \" and \', and finally \\. It does not decode \uXXXX or \xNN sequences, which stay as typed. The replacements run one after another rather than in a single pass, so a doubled backslash followed by a letter can be misread: the escaped path C:\\new\\table is turned into C:, a backslash, a real line break, ew, a backslash, a real tab and able. If your text contains escaped Windows paths, check the result by eye.

HTML unescape decodes any named or numeric entity using the browser itself, SQL unescape turns '' back into ', and Regex unescape removes the backslash from the regex special characters.

Where this is not enough

The escaped text is meant to sit inside a string literal you type yourself; add the surrounding quotes. For JSON, use the JSON tools, which produce strictly valid output. For untrusted input going into SQL, use parameterised queries, because doubling quotes does not cover every database's rules (MySQL, for example, also treats backslash as an escape character).

Frequently asked questions

Is escaping the same as encryption?

No. It only changes how special characters are written.

Does escaping stop SQL injection?

For real applications use parameterised queries; this tool is a convenience for text.

Why does my output have backslash-n?

Line breaks are written as \n in escaped strings.

Is my data uploaded?

No. This tool runs entirely in your browser, so what you type or paste is not sent to our servers.

Does it add the surrounding quotes?

No. The output is only the inside of the string, so add your own opening and closing quotes in the code.

Why did unescaping my Windows path produce odd characters?

Escape sequences are replaced one after another, so \\n and \\t in an escaped path can be read as a line break or tab. Unescape short fragments or fix the result manually.

Related tools

Explore all developer tools →