package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^val:\s*([^-\n]*?)(?:\s*-[^-]*-\s*(.*))?$`)
var str = `val: 1.25MG - OM - PO/TUBE
val:2.5 MG - OM - PO/TUBE
val: 18 UNITS(S)
val: 850 MG - TDS AFTER FOOD - SC (SUBCUTANEOUS)
val: 75 MG - OM - PO/TUBE`
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/