package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?mx)<([^\/>]+)>((([^\<]+)|(?R))*)<\/\1>`)
var str = `<ul><li><span>qwe</span><b></b></li><div>sometext</div></ul><div></div>.
<li><span>qwe</span><div>s</div></li>
<b></b>
<ul><li><span>qwe</span><b></b></li><div>sometext</div></ul><div></div>.
some text <tag>some|another|text</tag> and anything else
str = <<'EOT'
Это <!--пример текста--> с5
<a href="#">какой-то</a> <br>разметкой <br />
<b class="11">и</b> <amg src="1">
<area>непарными</area> <strong>
тегами</strong> и, <!--коментами-->,
<ul id="w"> <li id="id" class="class">1</li></ul><div></div>.
<u class="ну и даже так" />
EOT`
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/