package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(ABC)_([0-9]{4})_([0-9]+\.[0-9]+\.[0-9]+)(_[a-zA-Z])?(_[a-zA-Z]+)?\.xyz$`)
var str = `ABC_0000_0.0.0.xyz
Group 1 : ABC
Group 2 : 0000
Group 3 : 0.0.0
Group 4 : <empty>
Group 5 : <empty>
ABC_0001_0.1.0_N.xyz
Group 1 : ABC
Group 2 : 0001
Group 3 : 0.1.0
Group 4 : _N
Group 5 : <empty>
ABC_0002_1.1.2_foo.xyz
Group 1 : ABC
Group 2 : 0002
Group 3 : 1.1.2
Group 4 : <empty>
Group 5 : _foo
ABC_0002_42.42.42_N_bar.xyz
Group 1 : ABC
Group 2 : 0002
Group 3 : 42.42.42
Group 4 : _N
Group 5 : _bar`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/