CraftTools

String Escape / Unescape

Guide: Regex Cheat Sheet for Beginners

Nothing you enter or choose here leaves your device. This tool runs in your browser.

One string, many escapes

Escaping means changing characters that would break a string into a safe form. What counts as safe depends on where the string is going. Take this text, which has quotes, a line break, a path with backslashes, a tab and an apostrophe:

She said "hi"
Path: C:\temp\file.txt     (tab)    O'Brien
FormatWhat changes
JSON, JavaScript, Java, PythonQuotes become \", line breaks \n, tabs \t, backslashes doubled
HTML and XMLQuotes become &quot;, the apostrophe becomes &#39;, and &, < and > are converted
SQLThe apostrophe is doubled, so O'Brien becomes O''Brien
RegexBackslashes doubled and the full stop becomes \., so it matches a literal dot
CSVThe whole field is wrapped in quotes, and inner quotes are doubled

How to use the output

The result doesn't include the surrounding quotes, so you can paste it between your own. For a JSON string, wrap it in double quotes. For SQL, in single quotes. Choose Unescape to go the other way, for example to read what a log line with \n and \" really says.

When you'll need it

  • Putting a block of JSON inside another JSON value, as a string.
  • Pasting a multi-line message into a source file.
  • Matching a literal file name or a price like $9.99 in a regular expression.
  • Showing code samples in a web page.
  • Building a CSV field that contains commas or quotes.

The non-ASCII option

Tick it and characters like รฉ or an emoji are written as \uXXXX sequences. That's useful when a file or system only allows plain ASCII, or when you want text to survive being copied through something that mangles accents. The meaning is unchanged, and the program reading it turns the sequences back into letters.

A warning about SQL

Escaping a string isn't a safe way to build a database query. Doubling quotes helps with one problem and leaves others. In code, always use parameterized queries, which keep your data completely apart from the SQL. Use this tool for one-off scripts and quick checks, not for handling user input.

Common mistakes

  1. Escaping twice. If you see \\n in the output, the text was already escaped.
  2. Using the wrong format. A JSON string and a Python string look alike but differ in details like what's allowed after a backslash.
  3. Forgetting that regex and the string holding it are two layers. A regex that needs \d often has to be written \\d inside a code string.

Text stays in your browser. For HTML entities in more detail, use the HTML entity encoder. To build and test a pattern, try the regex tester, and for URL escaping, the Base64 encoder in URL mode.

Written by Akinrinmade Michael ยท Updated October 24, 2026

How to use

  1. 1Choose Escape or Unescape.
  2. 2Pick the format, such as JSON string or SQL string.
  3. 3Paste your text into the input box.
  4. 4Click Copy result.

Frequently asked questions

What gets escaped?

It depends on the format. Programming languages escape quotes, backslashes, line breaks and control characters. HTML and XML escape & < > and quotes. SQL doubles single quotes. Regex escapes characters like . * + ? and brackets. CSV wraps fields in quotes.

Should I include the surrounding quotes?

The result doesn't include them, so you can paste it between your own quotes. For example, use the JSON result inside double quotes.

What does escaping non-ASCII characters do?

It writes characters such as รฉ and emoji as \uXXXX sequences, which is useful when a file or API only allows plain ASCII.

Can this protect against SQL injection?

No. Escaping isn't a safe way to build SQL. Always use parameterized queries in your code.

Read the guides

Learn how this works and how to get the most from it.

Developer

Regex Cheat Sheet for Beginners

A plain-English guide to regular expressions: character classes, quantifiers, groups, flags and examples you can test.

3 min read

Developer

How to Format SQL So Anyone Can Read It

Simple formatting habits that make SQL queries easy to read and review, plus how to handle quotes and when a formatter helps.

3 min read

HTML Entity Encoder / Decoder

Encode special characters as HTML entities, or decode entities back to text.

Base64 & URL Encoder / Decoder

Encode and decode Base64 and URL-encoded text instantly.

JSON Formatter & Validator

Prettify, minify and validate JSON, with error line numbers.

Regex Tester

Test regular expressions live, with match highlighting and groups.