package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m).*told me to say.*`)
var str = `ex1: I am * years old
valid matches:
- "I am 24 years old"
- "I am twenty four years old"
ex2: what color is [my|your|his|her] (bright red|blue|green|lemon chiffon) *
valid matches:
- "what color is his lemon chiffon car"
- "what color is my some random text till the end of string"
ex3: [*] told me to say *
valid matches:
- "Bob and Alice told me to say hallelujah"
- "told me to say by nobody"`
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/