package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(([^"']*?)foo(.*)|(.*?)foo([^"']*))$`)
var str = `hello foo
hello "foo" and foo not 'foo'
Hello "foo" foo, how are "you" doing?
they "are foo and bar" and foo
This foo " is too a match
"foo" not bar but foo
This foo ' should be matched
Then foo said "foo bar", which didn't work
"This is the foo bar"
hello "foo"
hello "foo"
hello 'foo'
you said "my name is foo"
`
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/