package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^Start Group\r?\nName = "ITEM TYPE 2"\r?\n(?>(?!End Group$).*\r?\n)*End Group$`)
var str = `Start Group
Name = "ITEM TYPE 1"
ID = [ID_1]
stuff
stuff
stuff
End Group
Start Group
Name = "ITEM TYPE 2"
ID = [ID_2]
stuff
stuff
stuff
stuff
End Group
Start Group
Name = "ITEM TYPE 1"
ID = [ID_3]
stuff
End Group
Start Group
Name = "ITEM TYPE 2"
ID = [ID_4]
stuff
stuff
End Group`
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/