package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?s)[^\n]*\blittle\b(?:(?!\blittle\b|\bfleece\b).)*fleece[^\n]*(?:\n[^\n]*){4}`)
var str = `1.Mary had a little lamb,
2.Little lamb, little lamb,
3.Mary had a little lamb,
4.Its fleece was white as snow
5.And everywhere that Mary went,
6.Mary went, Mary went,
7.Everywhere that Mary went
8.The lamb was sure to go
9.It followed her to school one day
10.School one day, school one day
11.It followed her to school one day
12.Which was against the rules.`
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/