package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)<(?<tagName>\w+)(([^<]*\/>)|(.*?\/(\k<tagName>)>))`)
var str = ` <child name = "child_name1" type = "child_type1"> <subchild id = "1" auth="auth1">Value1</subchild> </child> <child name = "child_name2" type = "child_type2"> <subchild id = "2" auth="auth1">Value2</subchild> <subchild id = "3" auth="auth2">Value3</subchild> <subchild id = "4" auth="auth3"></subchild> <subchild id = "5" auth="auth3"/> </child>`
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/