package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)<!--(?!\s*?end-readmore-item\s*-->)[\s\S]*?-->`)
var str = `<div class="collapsible-item-body" data-defaulttext="Further text">Further
text</div>
<!-- end-readmore-item --></div>
</div>
<!-- -->
it only should match with <!-- --> but it's selecting everything except <!--
end-readmore-item -->
the usage of this is gonna be to remove all the HTML comments except <!--
end-readmore-item -->
<!-- Different comment -->
`
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/