package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(?!(?:(?!g1|g2).)*(?:g21|g22)(?:(?!g31|g32|g41|g42).)*(?:g11|g12)).*?(?:g11|g12).*$`)
var str = `'g11'
'g31 g11'
'g41g11'
'g11 g21 g11'
'anything or nothing g11 anything or nothing'
'anything or nothing g31 anything or nothing g11'
'anything'
''
'g31 g21 g11'
'g21 g11 g31'
`
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/