JavaScript RegExp \ooo Metacharacter

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Octal escape

What You’ll Learn

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

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.

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.

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.

📝 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).

⚡ Quick Reference

GoalOctalDecimalEquivalent
Letter A\10165\x41, \u0041
Letter a\14197\x61
Newline (LF)\01210\n, \x0A
Tab (HT)\0119\t, \x09
Digit 5\6553\x35
Max value\377255\xFF

📋 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

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.

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

The engine parses 101 as an octal number, converts it to decimal 65, and matches the character at that code point.

📈 Practical Patterns

Control characters and cross-notation comparison.

Example 2 — Match a Newline with \012

Octal 12 equals decimal 10, the line feed character.

JavaScript
const text = "line1\nline2";

console.log(/\012/.test(text));    // true
console.log(text.split(/\012/));  // ["line1", "line2"]
console.log(/\n/.test(text));      // true (equivalent)
Try It Yourself

How It Works

\012, \x0A, and \n all target the same control character. Octal is the oldest notation of the three.

Example 3 — Match Lowercase a with \141

Three-digit octal avoids confusion with backreference \1.

JavaScript
const word = "cat";

console.log(/\141/.test(word));  // true
console.log(word.match(/\141/)[0]); // "a"
console.log(parseInt("141", 8));   // 97
Try It Yourself

How It Works

Using three octal digits makes intent clear. \141 cannot be mistaken for backreference \14 + literal 1 in the same way short forms can.

Example 4 — Compare Octal, Hex, and Unicode for A

Three escape notations, one character.

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)
Try It Yourself

How It Works

Octal 101, hex 41, and Unicode 0041 all represent decimal 65. Choose the notation your team finds clearest.

Example 5 — One-, Two-, and Three-Digit Octal Forms

Octal escapes accept one to three digits, each 0–7.

JavaScript
console.log(parseInt("65", 8));   // 53 (digit "5")
console.log(/\65/.test("5"));     // true

console.log(parseInt("101", 8));  // 65 (letter A)
console.log(/\101/.test("A"));    // true

console.log(/\011/.test("a\tb")); // true (tab)
Try It Yourself

How It Works

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).

🚀 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.

Important Considerations

  • Legacy syntax — prefer \xHH or \uXXXX in new regex.
  • Backreferences\1\9 refer to capture groups, not octal digits.
  • Digits 0–7 only8 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.

📝 Notes

  • Octal escapes use digits 0–7 only (base 8).
  • \0 alone matches null; see \0 for details.
  • Previous metacharacter: \xHH hex byte escape.
  • Next topic: d indices modifier.
  • Convert octal to decimal in DevTools: parseInt("101", 8).
  • For new code, prefer \xHH over octal for readability.

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 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: Works everywhere but is legacy. Use \xHH or \uXXXX when writing new regex patterns.

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.

💡 Best Practices

✅ Do

  • 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

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
📈 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).

Continue to d indices modifier

Learn how the d flag adds start/end positions to match results.

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.

6 people found this page helpful