Python (re)

Octal Number Literal in PY

Match modern ECMAScript-style octal literals (`0o755`) — strict per ES6+ syntax.

Try it in the PY tester →

Pattern

regexPY
\b0[oO][0-7]+\b   (flags: g)

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

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 = 0o022

Matches

  • 0o755
  • 0o022

Input

fileMode := 0o644

Matches

  • 0o644

Input

no octal

No match

Same pattern, other engines

← Back to Octal Number Literal overview (all engines)