Account

What new tool do you want?

Developer Tools

String Escape / Unescape

Escape or unescape strings for JavaScript, JSON, HTML, XML, SQL, CSV and regular expressions — quotes, backslashes and newlines handled.

How to use

  1. 1Pick the language and whether to escape or unescape.
  2. 2Paste the string and copy the result.

Frequently asked questions

Why escape strings?

Quotes, backslashes and newlines have special meaning inside string literals. Escaping lets them appear as ordinary characters.

How are quotes escaped in SQL?

A single quote is doubled: O'Brien becomes O''Brien. Prefer parameterized queries over manual escaping in real code.

What does regex escaping do?

It puts a backslash before characters like . * + ? ( ) [ ] so they match literally instead of acting as operators.

A worked example across languages

The same input escapes completely differently depending on the target language, which is the whole point of the Language dropdown: O'Brien escapes to O''Brien for SQL (a doubled quote, SQL's own escaping convention), but a,"b" escapes to "a,""b""" for CSV (the entire field gets wrapped in quotes, and the internal quote doubles) — notice SQL and CSV both double quotes, but for different structural reasons and with different outer wrapping. The regex target instead escapes 1+1=2? to 1\+1=2\?, adding a backslash only before characters that mean something to a regex engine (+ and ? are quantifiers) — = and digits need no escaping since they have no regex meaning.

Why "escape for SQL" is a trap you should avoid in real code

The SQL escape mode here exists so you can see what a quoted string looks like, but the FAQ's own advice is the important part: prefer parameterized queries over manual string escaping in real application code. Doubling quotes defeats naive SQL injection via quote characters, but it's notoriously easy to get wrong at the edges (different quoting rules for different databases, encoding issues, second-order injection through data that was escaped once and re-inserted unescaped) — parameterized queries sidestep the entire class of bug by never building SQL through string concatenation in the first place.

Why unescaping can fail when escaping never does

Escaping always succeeds — there's always a valid escaped form of any string. Unescaping can fail, because not every sequence of characters is valid escaped syntax: a stray trailing backslash, or \u followed by fewer than 4 hex digits, isn't parseable as an escape sequence and the tool reports "check for a stray backslash or invalid escape" rather than guessing. This asymmetry is inherent to escaping schemes generally, not a quirk of this tool — it's the same reason a JSON.parse() call on malformed escaped JSON throws rather than returning a best-effort result.

Unescape is the only direction that can refuse the text

Language opens on the first choice, the one aimed at ordinary program strings, and the other choices are JSON, HTML, XML, SQL, and CSV. Mode opens on escape. Escape always returns a result. Unescape is the direction that can stop, and the message says the string cannot be unescaped and tells me to check for a stray backslash or an invalid escape. I do not get a half-converted line when that happens. A quote, a line break, and a tab in the sample are written with backslash forms on the way out, and those same forms come back as a real quote, a real line break, and a real tab on the way in.

Related tools

More: Developer Tools