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
\Ufollowed 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
\uXXXXsequences. - Plain C has no
\uin string literals at all — use\xHHfor 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:
| Language | Raw string syntax | Example |
|---|---|---|
| Python | r"..." | r"\d+\.\d+" |
| Go | backtick literal | `\d+\.\d+` |
| Rust | r#"..."# | r#"\d+\.\d+"# |
| JavaScript | String.raw\…“ | String.raw\\d+.\d+“ |
| C | no raw string syntax | must escape manually |
| Java | text 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.