package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^\d+\.[ \t]*([^-\r\n]+?)(?:$|[ \t]*-[ \t]*(.*))`)
var str = `4. Cost/Estimating
6. Supplier - Minor Material: Specialty
6. Supplier - Pressure Vessels & Filters
6. Supplier - Pumps
6. Supplier - Minor Material: Valves
6. Supplier - Minor Material: Specialty
6. Supplier - Other Major Equipment
7. Manufacturing
8. Project Management
9. Order Release (OTR) - Commercial Documents
9. Order Release (OTR) - Hand-Off
6. Supplier - Compressors, Drivers & Refrig. Units`
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/