package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?s)(?<=:).*?(?=(?:\r?\n)+[^\n]*$)`)
var str = `This is the title: \ titles always have a colon
This is a regular sentence.
A sentence always ends with a period.
A sentence can
span multiple lines.
A sentence can contain numbers like 123.
The phrase can also contain "text enclosed in double quotes" or 'text enclosed in single quotes'.
Other symbols that may appear in sentences are
the comma ,
the semicolon ;
the dollar sign $
parentheses ( )
the plus sign + the minus sign - and the square brackets[ ].
This is an isolated phrase that the regular expression should not match.`
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/