package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?im)(.*)\s+([0-9]+(\-[0-9]+)?\s+)?((w|q)[0-9]+(\s+)?)(\..*)$`)
var str = `test test 1970-2020 w15.txt
test 1970-2020 w15.csv
test 1990-99 q1.txt
test 1981 w15 .csv
test test w15.csv`
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/