package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)(longword1)(longword2)|.*\K(?1).*(?2)|.*\K(?2).*(?1)`)
var str = `A longword1 B longword2 C
A longword2 B longword1 C
A longword1 B longword1 C
A longword2 B longword2 C
A longword1 B
A longword2 C
`
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/