The \ooo form is a legacy octal escape: a backslash followed by one to three octal digits (0–7). It matches the character at that numeric value—for example, \101 is capital A and \012 is a newline. You will mostly see this in older code; modern patterns prefer \xHH or \uXXXX.
01
Base 8
Digits 0–7
02
1–3 digits
\65 … \377
03
\101
Letter A
04
\012
Newline
05
vs \x
Octal vs hex
06
Legacy
Prefer hex
Fundamentals
Introduction
Before hex (\xHH) and Unicode (\uXXXX) escapes became standard, many languages—including JavaScript—allowed octal numeric escapes. Each digit after the backslash must be 0–7, and you may write one, two, or three digits.
Octal escapes still work in JavaScript regular expressions today, but they are considered legacy. They remain important for reading old scripts and understanding how numeric character codes relate across octal, decimal, and hex notation.
Concept
Understanding the Octal \ooo Escape
An octal escape matches one character whose code unit equals the octal number. Octal 101 equals decimal 65, which is the letter A.
JavaScript
/\101/.test("A"); // true (octal 101 = dec 65)
/\141/.test("a"); // true (octal 141 = dec 97)
/\012/.test("a\nb"); // true (octal 12 = dec 10 = LF)
"A" === "\101"; // true in strings too
The maximum value is 377 octal (255 decimal). Values above that cannot be expressed with a three-digit octal escape.
💡
Beginner Tip
In regex patterns, \1 through \9 usually mean backreferences to capture groups—not octal digits. To match the character with code 1, use \001, or prefer \x01 instead.
Usage
How to Use Octal Escapes in JavaScript
Octal escapes appear in legacy patterns and string literals:
JavaScript
/\101/.test("ABC"); // true (A at start)
"line1\012line2".split(/\012/); // split on LF
/\011/.test("a\tb"); // true (octal 11 = tab)
parseInt("101", 8); // 65 — convert octal to decimal
When writing new regex, reach for \xHH or \uXXXX instead. They are easier to read and avoid clashes with backreferences.
Foundation
📝 Syntax
JavaScript
\o // one octal digit (0-7)
\oo // two octal digits
\ooo // three octal digits (max \377)
\101 // letter A (octal 101 = dec 65)
\012 // line feed (same as \n)
\011 // horizontal tab (same as \t)
\0 // null when not followed by 0-7
Common patterns
/\101/ — match capital A by octal code.
/\141/ — match lowercase a (octal 141).
/\012/g — find line feed characters.
/\011/ — match tab (octal 11 = decimal 9).
Cheat Sheet
⚡ Quick Reference
Goal
Octal
Decimal
Equivalent
Letter A
\101
65
\x41, \u0041
Letter a
\141
97
\x61
Newline (LF)
\012
10
\n, \x0A
Tab (HT)
\011
9
\t, \x09
Digit 5
\65
53
\x35
Max value
\377
255
\xFF
Compare
📋 Octal vs hex vs Unicode vs shorthands
Four numeric escape styles for the same ASCII character A (code 65).
Octal (legacy)
\101
Digits 0–7 only
Hex byte
\x41
Preferred today
Unicode
\u0041
Four hex digits
Literal
A
Simplest form
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it links. Examples cover letter matching, newlines, lowercase octal, cross-escape comparison, and one- vs two-digit forms.
📚 Getting Started
Match a character using its octal code.
Example 1 — Match the Letter A with \101
Octal 101 equals decimal 65, the ASCII code for capital A.
The parser consumes up to three octal digits. Shorter forms like \65 match different characters than \065 would if zero-padded—always verify the decimal value with parseInt(value, 8).
Applications
🚀 Common Use Cases
Reading legacy regex — decode old patterns that use octal codes.
Maintenance — understand historic scripts before migrating to hex.
Learning number bases — connect octal, decimal, and hex character codes.
Control characters — recognize \012 (LF) and \011 (tab) in old dumps.
Documentation — translate octal tables from Unix-era references.
Migration — convert octal escapes to \xHH for modern codebases.
Watch Out
Important Considerations
Legacy syntax — prefer \xHH or \uXXXX in new regex.
Backreferences — \1–\9 refer to capture groups, not octal digits.
Digits 0–7 only — 8 and 9 are not valid octal digits.
Max \377 — three octal digits cap at 255 decimal; no emoji or BMP+ via octal alone.
Not hex — octal \101 is not the same notation as hex \x101 (which would be invalid/consumed differently).
🧠 How Octal Escapes Match Characters
1
Read digits
After \, consume up to three octal digits (0–7).
Parse
2
Convert base 8
101 octal → 65 decimal → character “A”.
Convert
3
Match character
Compare the resolved character to the next input code unit.
Match
4
📚
Continue pattern
Match found → advance. Mismatch → fail or backtrack.
Convert octal to decimal in DevTools: parseInt("101", 8).
For new code, prefer \xHH over octal for readability.
Compatibility
Browser & Runtime Support
Octal escapes in regular expressions are legacy JavaScript syntax supported since ES3.
✓ Baseline · ES3+
RegExp octal \ooo
Supported in all browsers for backward compatibility. Prefer hex or Unicode escapes in new projects.
99%Universal (legacy)
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
\oooExcellent
Bottom line: Works everywhere but is legacy. Use \xHH or \uXXXX when writing new regex patterns.
Wrap Up
Conclusion
The octal \ooo escape matches a character by its octal code (one to three digits, 0–7). Examples like \101 (A) and \012 (newline) appear in legacy JavaScript, but modern code should prefer \xHH or \uXXXX.
Watch for backreference conflicts with \1– \9, verify values with parseInt(digits, 8), and migrate old patterns when you can. Next, learn the d indices modifier.
Use octal when reading or maintaining legacy regex
Verify codes with parseInt("101", 8)
Use three digits when clarity matters (\141)
Migrate to \xHH when modernizing code
Compare with hex/Unicode tables when debugging
❌ Don’t
Write new patterns with octal if hex is clearer
Assume \1 is octal (it is usually a backreference)
Confuse octal \101 with hex notation
Use digits 8 or 9 in octal escapes
Expect octal to express code points above 255
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about octal \ooo
Decode legacy regex by converting base-8 digits to character codes.
5
Core concepts
📚01
Base 8
Digits 0–7.
Syntax
📈02
\101
Letter A.
Example
🚫03
\012
Newline.
Control
🔒04
\1–\9
Backrefs.
Pitfall
🔢05
\xHH
Prefer this.
Modern
❓ Frequently Asked Questions
A backslash followed by one to three octal digits (0–7) matches the character with that code point. For example, \101 matches A (octal 101 = decimal 65) and \012 matches a line feed.
One, two, or three octal digits, each from 0 to 7. The value must not exceed 377 octal (255 decimal). Examples: \65, \101, and \011 are all valid.
No. Octal uses digits 0–7 only (base 8). Hex \xHH uses hexadecimal digits 0–9 and A–F (base 16). \101 (octal) equals \x41 (hex)—both match A—but the syntax rules differ.
In a regex pattern, \1 through \9 are usually backreferences to capture groups, not octal escapes. Use two or three digits (such as \141 for lowercase a) or prefer \xHH / \uXXXX to avoid ambiguity.
Generally no. Octal is a legacy form. Modern code should prefer \xHH for bytes, \uXXXX for Unicode, or readable shorthands like \n and \t. Octal remains useful when reading old patterns.
Octal escapes are legacy JavaScript syntax supported since ES3. They work in all browsers, but new projects should favor hex or Unicode escapes for clarity.
Did you know?
Unix file permissions like chmod 755 use octal notation. The same base-8 math applies to regex octal escapes: each digit place is a power of 8, which is why \101 equals decimal 65 (1×64 + 0×8 + 1).