regexp/syntax

Guided tour · Formatting & Strings · pkg.go.dev →

Parse a regular expression into an AST. Needed only if you're building tooling on top of regex syntax.

Parse a pattern into a Regexp tree

Parse and Simplify

re, err := syntax.Parse(`a(b|c)+`, syntax.Perl)
if err != nil { log.Fatal(err) }
fmt.Println(re)            // tree form
fmt.Println(re.Simplify())