Octal Number Literal in JS
Match modern ECMAScript-style octal literals (`0o755`) — strict per ES6+ syntax.
Try it in the JS tester →Pattern
regexJS
\b0[oO][0-7]+\b (flags: g)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).
How the pattern 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
—