Numbersflags: g
Octal Number Literal
Match modern ECMAScript-style octal literals (`0o755`) — strict per ES6+ syntax.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("\\b0[oO][0-7]+\\b", "g");
const input = "perms = 0o755; mask = 0o022";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
pyPython
import re
pattern = re.compile(r"\b0[oO][0-7]+\b")
input_text = "perms = 0o755; mask = 0o022"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\b0[oO][0-7]+\b`)
input := `perms = 0o755; mask = 0o022`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
regexengine-agnostic
\b0[oO][0-7]+\b (flags: g)Raw source: \b0[oO][0-7]+\b
How it works
\b is a word boundary. 0[oO] requires the modern ES6 octal prefix (case-insensitive on the o). [0-7]+ matches one or more octal digits (0–7). \b prevents matching into adjacent letters. Note: the loose `0755` form (no o) is technically a legacy octal in some languages but is dangerous in JS strict mode — this pattern requires the explicit `0o` prefix.
Examples
Input
perms = 0o755; mask = 0o022Matches
0o7550o022
Input
fileMode := 0o644Matches
0o644
Input
no octalNo match
—Common use cases
- •Source-code analysis for file-mode literals
- •Unix permission detection in IaC code
- •Linting against deprecated octal forms
- •Educational / tutorial parsing
Related patterns
Binary Number Literal
NumbersMatch binary number literals like `0b1010` or `0B11110000`.
Hexadecimal Number Literal
NumbersMatch hexadecimal number literals like `0xFF`, `0x1A2B`, or `0XdeadBeef`.
Decimal Number
NumbersMatches decimal numbers, including integers and negatives.
Float / Scientific Number
NumbersMatch floating-point and scientific-notation numbers including `1.5`, `.25`, `1e10`, `-3.14E-2`.