CoderTools

Escape/Unescape Tool

Escape and unescape strings between multiple formats

Escape/Unescape Documentation

What is Character Escaping?

Character escaping is the process of converting special characters into escape sequences for safe use in specific contexts. For example, in a JavaScript string, double quotes need to be written as \" to be represented correctly.

Supported Formats

JavaScript Escape

Escape special characters in JavaScript strings, including quotes, newlines, tabs, etc.

JSON Escape

Convert strings to valid JSON string format, handling double quotes and control characters.

HTML Escape

Convert HTML special characters to HTML entities to prevent XSS attacks.

XML Escape

Convert XML special characters to XML entities to ensure XML document validity.

CSV Escape

Properly handle commas, quotes, and newlines in CSV format.

SQL Escape

Escape single quotes in SQL strings to prevent SQL injection attacks.

Regular Expression Escape

Escape special characters in regular expressions to match them literally.

C String Escape

Escape special characters in C/C++ strings, including octal and hexadecimal sequences.

Java String Escape

Escape special characters in Java strings, including Unicode escape sequences.

Common Use Cases

  • Embed strings containing special characters in code
  • Generate valid JSON data
  • Prevent HTML and SQL injection attacks
  • Handle special characters in CSV files
  • Create safe regular expression patterns

Escape Rules Reference

JavaScript/JSON Escape Rules

Original Character Escaped Sequence Description
\\\Backslash itself
'\'Single quote
"\"Double quote
LF\nNewline
CR\rCarriage return
TAB\tTab
BS\bBackspace
FF\fForm feed
U+XXXX\uXXXXUnicode character (4 hex digits)

HTML Escape Rules

Original Character Escaped Sequence Description
<&lt;Less than
>&gt;Greater than
&&amp;Ampersand
"&quot;Double quote
'&#39;Single quote
 &nbsp;Non-breaking space

XML Escape Rules

Original Character Escaped Sequence Description
<&lt;Less than
>&gt;Greater than
&&amp;Ampersand
"&quot;Double quote
'&apos;Single quote/apostrophe

CSV Escape Rules

Original Character Escaped Sequence Description
"""Wrap field in quotes and double the quote
,"...,"Wrap field containing comma in quotes
LF/CR"...\n"Wrap field containing newline in quotes

SQL Escape Rules

Original Character Escaped Sequence Description
'''Double the single quote
\\\Double the backslash (MySQL mode)

Regular Expression Escape Rules

Original Character Escaped Sequence Description
\\\Escape backslash
.\.Escape any character match
*\*Escape zero or more
+\+Escape one or more
?\?Escape zero or one
^\^Escape start of line anchor
$\$Escape end of line anchor
|\|Escape alternation operator
[ ]\[ \]Escape character class brackets
( )\( \)Escape grouping parentheses
{ }\{ \}Escape quantifier braces

C/C++ String Escape Rules

Original Character Escaped Sequence Description
\\\Backslash itself
'\'Single quote
"\"Double quote
NUL\0Null character
BEL\aAlert/bell
LF\nNewline
CR\rCarriage return
TAB\tTab
0-377\nnnOctal value (1-3 digits)
00-FF\xnnHexadecimal value (2 digits)

Java String Escape Rules

Original Character Escaped Sequence Description
\\\Backslash itself
'\'Single quote
"\"Double quote
LF\nNewline
CR\rCarriage return
TAB\tTab
BS\bBackspace
FF\fForm feed
0-377\nnnOctal value (1-3 digits)
U+XXXX\uXXXXUnicode character (4 hex digits)

Related Tools