You could use a string literal (with back quote) in order to include a single quote, with a capturing group:
re := regexp.MustCompile(`(?s)bus'.\s+(.*?nuts)`)
See this example:
var source_txt = `bus driver drove steady although the bus's steering was going nuts.`
func main() {
fmt.Printf("Experiment with regular expressions.
")
fmt.Printf("source text:
")
fmt.Println("--------------------------------")
fmt.Printf("%s
", source_txt)
fmt.Println("--------------------------------")
// a regular expression
regex := regexp.MustCompile(`(?s)bus'.\s+(.*?nuts)`)
fmt.Printf("regex: '%v'
", regex)
matches := regex.FindStringSubmatch(source_txt)
for i, v := range matches {
fmt.Printf("match %2d: '%s'
", i+1, v)
}
}
Output:
Experiment with regular expressions.
source text:
--------------------------------
bus driver drove steady although the bus's steering was going nuts.
--------------------------------
regex: '(?s)bus'.\s+(.*?nuts)'
match 1: 'bus's steering was going nuts'
match 2: 'steering was going nuts'
The FindStringSubmatch()
:
identifying the leftmost match of the regular expression in s and the matches, if any, of its subexpressions
The match[1]
would be the first capturing group.