package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(?=-.*D$|\d.*C$)-?(?=(?:\d,?){1,13}\.)(?:0|[1-9]\d{0,2}(?:,\d{3})*)\.\d{2} [DC]$`)
var str = `-0.48 D
-1.00 D
-2,000.00 D
-100,000.56 D
-100,000.00 D
-1,123,456.43 D
-1,123,456,000,000.43 D
-10,123,456,000,000.43 D
-1,123,456.43 C
-3,000,62.45 D
-03,000.45 D
-.23 D
0.23 C
1.00 C
2,000.00 C
100,000.56 C
100,000.00 C
1,123,456.43 C
1,123,456,000,000.43 C
10,123,456,000,000.43 C
`
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/