JavaScript RegExp \ooo Octal Escape

Beginner
6 min read
Updated: Oct 2026
3 examples
Legacy

What Is \ooo?

\ooo is a legacy octal escape: a backslash plus one to three digits from 0–7. It matches the character at that code — for example \101 is A, and \012 is a newline.

Remember
\ooo     → character at octal value ooo

\101     → "A"   (octal 101 = dec 65)
\141     → "a"   (octal 141 = dec 97)
\012     → newline  (same as \n)
\011     → tab      (same as \t)

digits: 0–7 only
length: 1–3 digits (max \377 = 255)
UsePrefer
New patterns\xHH or \uXXXX
Letter A by code\x41 (or legacy \101)
Newline / tab\n / \t

How to Use \ooo

Write one to three octal digits after \, then test as usual — mainly when reading legacy code.

  1. Convert the character code to octal (digits 0–7 only), up to three digits (max 377).
  2. Put it in a pattern without the u/v flag — e.g. /\101/.
  3. Call test, match, or split on your string.
  4. For new code, rewrite to \xHH, \uXXXX, or a shorthand like \n.
PieceRequired?Role
\ + digitsYesStarts an octal escape (1–3 digits, 0–7)
Max value—\377 octal = 255 decimal
Unicode modeAvoid/…/u rejects octal escapes

Pseudocode

Pseudocode
pattern contains "\" + ooo   // ooo = 1–3 digits, each 0–7

value = parse_octal(ooo)     // 0 … 255
target = character(value)

for each char in input:
    if char == target:
        match this position
    else:
        try next / fail

Cheat Sheet

Keep these octal facts handy when reading older patterns.

TopicDetail
Syntax\o / \oo / \ooo (digits 0–7)
Letter A\101 (= \x41)
Letter a\141 (= \x61)
Newline (LF)\012 or \n
Tab (HT)\011 or \t
ConvertparseInt("101", 8) → 65
vs backrefs\1–\9 usually mean capture groups
StatusLegacy (Annex B) — prefer \xHH

Live Preview

Pick an octal escape and see what character it matches (and its hex twin).

Browser demo of legacy \ooo — same idea as the examples below.

Result
/\101/.test("ABC")
→ true

/* octal 101 = dec 65 = "A" (= \x41) */

JavaScript Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Match the Letter A with \101

Use an octal escape to test for the character at code 65.

JavaScript
console.log(/\101/.test("A"));    // true
console.log(/\101/.test("B"));    // false
console.log(/\101/.test("ABC"));  // true
console.log(parseInt("101", 8));  // 65
Try It Yourself

How It Works

  1. Read octal digits. \101 means base-8 value 101.
  2. Convert to decimal. 1×64 + 0×8 + 1 = 65 → capital A.
  3. Test matches. "A" and "ABC" succeed; "B" fails.
  4. Check with parseInt. parseInt("101", 8) confirms the decimal code.

Example 2 — Newline \012 and Tab \011

Detect control characters with three-digit octal forms (same as \n and \t).

JavaScript
const text = "line1\nline2";
const row = "name\tage";

console.log(/\012/.test(text));   // true
console.log(text.split(/\012/));  // ["line1", "line2"]
console.log(/\011/.test(row));    // true
console.log(row.split(/\011/));   // ["name", "age"]
Try It Yourself

How It Works

  1. Line feed is octal 12. \012 matches the same character as \n.
  2. Three digits avoid backrefs. Short \1 would look like a capture-group reference.
  3. Tab is octal 11. \011 matches the same character as \t.
  4. Split works the same. Use these when an old pattern lists control codes in octal.

Example 3 — Octal \101 vs Hex \x41

Confirm that octal and hex escapes match the same ASCII letter — then prefer hex for new code.

JavaScript
const ch = "A";

console.log(/\101/.test(ch));   // true (octal)
console.log(/\x41/.test(ch));   // true (hex)
console.log(/\u0041/.test(ch)); // true (Unicode)

// Modern preference for the same character:
console.log(/\x41/.test(ch));   // prefer this in new code
Try It Yourself

How It Works

  1. Same character, three notations. Octal 101, hex 41, and Unicode 0041 all mean A.
  2. Octal is legacy. Useful when maintaining old patterns.
  3. Hex is clearer for bytes. Prefer \x41 in new regex.
  4. Unicode for wider range. Use \uXXXX above 255 or when using the u flag.

Edge Cases & Pitfalls

Check these before relying on octal escapes.

backref

\1–\9 are usually backreferences

Short forms clash with capture groups. Prefer three digits (\012) or, better, \x0A / \n.

unicode

Fails with the u / v flag

Unicode mode rejects octal escapes (SyntaxError). Use \xHH or \uXXXX.

digits

Only digits 0–7

8 and 9 are not octal digits. Max value is \377 (255 decimal).

legacy

Prefer \xHH in new code

Octal remains for reading old patterns. New regex should use hex, Unicode, or readable shorthands.

Browser & Runtime Support

Octal escapes in RegExp are legacy JavaScript syntax (ECMAScript Annex B), supported since ES3 in non-Unicode patterns.

✓ Legacy · Annex B

RegExp \ooo

Works in every browser without the u/v flag. Unicode mode rejects octal. Prefer \xHH or \uXXXX for new code.

99% Universal (legacy)
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
\ooo Excellent

Bottom line: Safe to read and run in legacy patterns. For new code, migrate to \xHH, \uXXXX, or shorthands like \n — and never combine octal with the u flag.

Performance Notes

ApproachCostBest for
/\101/O(n) scanReading legacy patterns
/\x41/O(n) scanNew code (same runtime cost, clearer)
/A/ literalO(n) scanReadable ASCII letters

Octal escapes resolve at compile time to a single character — same match cost as \x41 or a literal A. Choose notation for clarity and Unicode-mode compatibility, not speed.

Key Takeaways

  • Role: match one character by 1–3 octal digits (0–7), max \377.
  • Example: \101 = A = \x41.
  • Legacy: prefer \xHH / \uXXXX in new code.
  • Trap: \1–\9 are usually backreferences; u mode forbids octal.

One line: learn \ooo to read legacy regex — write new patterns with \xHH, \uXXXX, or \n/\t.

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 (base 8). Hex \xHH uses 0–9 and A–F (base 16). \101 (octal) equals \x41 (hex)—both match A—but the rules differ. Prefer \xHH in new code.
In a regex pattern, \1 through \9 are usually backreferences to capture groups, not octal. Use three digits (such as \141) or prefer \xHH / \uXXXX to avoid ambiguity.
Generally no. Octal is a legacy form (ECMAScript Annex B). Prefer \xHH for bytes, \uXXXX for Unicode, or shorthands like \n and \t. Learn octal mainly to read older patterns.
No. In Unicode mode (/…/u or /…/v), octal escapes are a SyntaxError. Use \xHH or \uXXXX instead.

Next: d modifier

Learn the RegExp d flag for match indices (hasIndices).

d modifier tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful