package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)<section.*id="section[\d]*"[\s\S]*?<\/section>`)
var str = `<!DOCTYPE html>
<html lang="en">
<head>
<title>Whatever</title>
</head>
<body>
<section class="all-classes" id="section1-do-not-remove-section">
content2
content
</section>
<section class="all-classes" id="section2">
content
content2
</section>
</body>
<section class="all-classes" id="section3">
content
<div class="all-classes" id="section4">
anything
whatever
</div>
</section>
<section class="all-classes" id="section5-do-not-remove-section">
content
</section>
<section class="all-classes" id="section6">
content
</section>
<section class="all-classes" id="section7">
content
</section>
`
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/