package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?ms)^config\s.*?(?=(?:\r?\n)+(?:config\s|\Z))`)
var str = `config vdom
edit root
next
edit test
next
edit test2
next
end
config global
...
...
...
end
end
config vdom
edit root
config system
...
end
config ...
...
...
......
...
end
end
config vdom
edit test
config system
...
end
config ...
...
...
......
...
end
end
config vdom
edit test2
config system
...
end
config ...
...
...
...
end
end
`
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/