Getting Parse Tree of a Regex in Go

Viewed 1172

I tried using the regex.syntax module to access the individual tokens of a parsed regular expression without success: the only thing I'm able to output is a simplified/optimized version of the regex.

Code:

package main

import (
    "fmt"
    "regexp/syntax"
)

func main() {
    p, e := syntax.Parse(`[0120-2]@[ab][0-9]`, 'i')

    fmt.Println(p)
    fmt.Println(e)
}

Output:

[0-2](?i:@)[A-Ba-b][0-9]
<nil>

Can someone give me a simple example of how to traverse and output its parse tree?

1 Answers
Related