package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?i)([+-]? ?[0-9]{1,3}(deg|°|\*)) ?([0-9]{1,2}\.?[0-9]*?(min|'|’| ))? ?([0-9]{1,2}\.?[0-9]*?(sec|"|”| ))?( ?[NSEW]?)`)
var str = `This is the start of a validator for Degrees Minutes Seconds for GeoMapping
38° 24' 55" -78deg 28' 52" W
12345 North south aasdf#asdf
125415 S asdf/asdf/asdf
asdf"ASDF""asdf'
!@#$%^&*()_+.[]__ ASDF __ASDF__
38° 24' -78deg 28' 52" W
38° 24' 55", -78deg 28' 52" W
-39.1234567 77.123456
77.123456
38.0818651958795, -78.4788168125323
38 -78
38N -78
38 N -78
38 N, -78
`
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/