package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(?=.*\.(txt|pdf|csv|docx|html|jpeg)$)(?!.*\-bad\.\1$).+\.\1$`)
var str = `this-file-bad.txt
this-file.txt
this-file.txt_t
.txt
f.txt
this-file-bad.csv
this-file.csv
.csv
f.docx
`
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/