package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^[A-Z0-9]+(?:-[A-Z0-9]+)?(?:,[A-Z0-9]+(?:-[A-Z0-9]+)?)*$`)
var str = `//Valid Values
D1
DF2,AB2
D1-2
A1, A2
D1 - 2
1 - FH15
1-R3
1,D2
1,H5,8,S4
1 , H5, 8, S4
1, D2, D6-8, 6-9
1,D2,D6-8,6-9,G2,8
1-D3,TT6-8
1-D3, TT6-8
1-3, VB8, 11-SD13, R15
//Invalid values
1*, 3
,1,F2
-1-TG3
12-D4,
D1-F2-
1- F2- 4
D10,/
1234s
F4-,8
4,-H5
D3-F-G7
D3 - F - G7
4 , - H5
1*,D
12 - D4`
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/