package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?mi)\bch.*?\K\b(?:\d+|VI{0,3}|I(?:[XV]|I{0,2}))\b`)
var str = `"chapter some word 12"
"chapter some word 12 some word"
"chapter some word I some word"
"chapter some word II some word"
"chapter some word III some word"
"chapter some word iv some word"
"chapter some word v some word"
"chapter some word vi some word"
"chapter some word vii some word"
"chapter some word viI some word"
"chapter some word ix some word"
"chapter some word x some word"
"chapter some word xi some word"
`
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/