Escape Sequences Reference

Language escape sequences for C, Python, JS, Java, Go, Rust in one table.

A cross-language escape-sequence cheatsheet covering string, unicode and raw-string syntax for C, Python, JavaScript, Java, Go and Rust. Filter by language or search by meaning. Runs entirely in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What is the difference between \n and \r\n?

\n is a line feed (LF, 0x0A) and \r is a carriage return (CR, 0x0D). Unix line endings use a single \n, while Windows text files use \r\n together. Classic Mac OS used a lone \r.

This is a cross-language reference for the escape sequences you write inside string and character literals — the backslash codes such as \n, \t, \xHH and \uXXXX. It is built for developers who switch between C, Python, JavaScript, Java, Go and Rust and need to know which escape a given language actually understands, because the rules differ in subtle and bug-prone ways.

How escape sequences work

An escape sequence begins with a backslash and is replaced by the compiler or interpreter with a single character (or byte sequence) when the literal is parsed. The backslash signals: “the next character is not literal, it is an instruction.” The most portable sequences work in every language covered here:

  • \n — newline (LF, 0x0A)
  • \r — carriage return (CR, 0x0D)
  • \t — horizontal tab (0x09)
  • \\ — a literal backslash
  • \" — a double quote inside a double-quoted string
  • \' — a single quote inside a single-quoted string (not all languages)

Where languages diverge: a practical guide

Unicode escapes are the most commonly confused area. In JavaScript, Java, Go, Python, and Rust, \uXXXX encodes a Unicode code point in exactly four hex digits (BMP range U+0000 to U+FFFF). Beyond the BMP, the languages differ:

  • JavaScript and Rust support \u{...} with a variable number of hex digits, covering the full Unicode range including emoji and supplementary planes.
  • Python uses \U followed by exactly eight hex digits for code points above U+FFFF.
  • Java requires a surrogate pair for code points above U+FFFF, encoded as two \uXXXX sequences.
  • Plain C has no \u in string literals at all — use \xHH for arbitrary bytes or rely on wide-character literals.

Hex escapes (\xHH) are supported in C, Python, JavaScript, Java, Go, and Rust, but they mean slightly different things. In C and Go they encode a byte, not a Unicode code point. In Python 3 \xHH in a byte string encodes a byte, while in a regular str it encodes a Unicode code point in the range U+0000 to U+00FF.

Octal escapes (\NNN with up to three octal digits) exist in C, Python, and Go. They are explicitly forbidden in JavaScript strict mode and not available in Java string literals. Prefer \xHH for portability.

The null terminator \0 works in all six languages to produce a zero byte. In C it terminates a string; in the others it is a valid character that can appear mid-string.

Raw strings and when to use them

When you need backslashes taken literally — for regular-expression patterns or Windows paths — reach for a raw string instead of doubling every backslash. Syntax by language:

LanguageRaw string syntaxExample
Pythonr"..."r"\d+\.\d+"
Gobacktick literal`\d+\.\d+`
Rustr#"..."#r#"\d+\.\d+"#
JavaScriptString.raw\…“String.raw\\d+.\d+“
Cno raw string syntaxmust escape manually
Javatext blocks (""") in Java 13+limited raw semantics

Raw strings are the recommended way to write regular expressions in every language that supports them, because the regex syntax itself uses backslashes heavily and doubling them obscures the pattern’s meaning.

Everything runs in your browser; nothing is uploaded.