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