package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(?!.*<amb(?:(?!<\/amb).)+<amb).+$`)
var str = `anything <amb id="1">word1</amb> anything <amb id="2">word2</amb> anything // Ok
anything <amb id="1">anything<amb id="2">word2</amb>anything</amb> // KO
anything <amb id="1">word1</amb> sss anything <amb id="1">word1</amb> ddd anything <amb id="1">word1</amb> ddd anything <amb id="1">word1 anything <amb id="1">word1</amb> sss </amb>`
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/