Backslash Escaper & Unescaper

Escape special characters with C-style backslash sequences

Free backslash escape tool — convert newlines, tabs, nulls and other control characters to C-style sequences like \n, \t and \xHH, and reverse it. Runs entirely in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What characters get escaped?

Control characters become readable sequences: newline as \n, tab as \t, carriage return as \r, null as \0, plus \v, \f and \b. Any other character below code point 32 (and DEL, 0x7f) becomes \xHH. Backslash, single quote and double quote are also escaped.

The backslash escaper and unescaper converts hard-to-see control characters into printable C-style escape sequences, and turns those sequences back into the raw characters they represent. It is the everyday tool for embedding multi-line text, tabs, binary bytes, and Unicode codepoints safely inside source code, configuration files, SQL strings, and shell scripts.

How it works

Escaping (raw text → escape sequences)

The escaper walks through your text one character at a time and converts each special character to its backslash sequence:

Raw characterCode pointEscaped
Null byte0x00\0
Backspace0x08\b
Tab0x09\t
Newline (LF)0x0A\n
Form feed0x0C\f
Carriage return (CR)0x0D\r
Vertical tab0x0B\v
Backslash0x5C\\
Single quote0x27\'
Double quote0x22\"
DEL0x7F\x7F
Other non-printable< 0x20\xHH

Any other non-printable byte (code point below 32 or DEL at 0x7f) that does not have a named sequence is written as a two-digit hex escape \xHH.

Unescaping (escape sequences → raw characters)

The unescaper scans for a backslash, reads the following character(s), and emits the matching raw byte. It handles:

  • Single-letter sequences: \n, \t, \r, \0, \v, \f, \b, \\, \', \"
  • Two-digit hex: \xHH (for example \x1B for ESC)
  • Four-digit Unicode: \uXXXX (for example é for é)

If a sequence is incomplete or unrecognised, the characters are kept literally so your data is never silently dropped or corrupted.

Worked example

The two-line string with a tab separator:

Hello\tworld\nLine 2

Pasting that exact text into the unescape field restores the original tab between “Hello” and “world” and the newline at “Line 2”. Round-tripping is lossless for all supported sequences.

When to use this vs other encoders

Escaping methodUse caseTool
C-style backslashC, C++, Java, C#, shell strings, many config formatsThis tool
JSON string escapingJSON values (stricter subset of C-style)JSON encoder
URL / percent encodingQuery strings, path segmentsURL encoder
HTML entity encodingHTML text, attribute valuesHTML escaper
Base64Binary data safe for text transportBase64 encoder

This tool produces C-style sequences recognised by C, C++, Java, Python, JavaScript, Go, Ruby and most configuration file parsers. It is not a JSON encoder (which has a stricter subset of the same sequences and no \xHH) and not a URL encoder (which uses %HH instead of \xHH).

Practical tips

  • Paste log lines into string literals: escape before pasting so editors do not interpret embedded newlines as line breaks in the code.
  • Hex escapes are case-insensitive here: \x0A and \x0a both decode to a newline (LF). Most parsers are the same.
  • Invalid sequences pass through unchanged: \q is not a valid sequence; it will appear literally as \q in the output rather than being silently dropped.