package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(?<good>\b(?:\w+\.)*(?:alsogood|good)\.com(?::\w+)?\b)(?: +\g<good>)*$`)
var str = `test.good.com:3 great.alsogood.com:latest test2.good.com
foo.bar.good.com:1
I would like it to match the previous strings but not match something like these:
test.good.com:3 another.bad.com great.good.com
foo.bad.com:1`
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/