package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(?:\+44\s?|0)[1238]\d\s?(?:\d\s?){7,8}$`)
var str = `# Standard
01386 444400
01386444400
+441386444400
+44 1386 444400
+44 1386444400
# 5 Digit
01386 41204
0138641204
+44138641204
+44 1386 41204
+44 138641204
# 3 Digit area codes (e.g. London)
+442074343046
02074343046
020 74343046
020 7434 3046
# 4 Digit area codes (e.g. Leeds)
+441133971337
01133971337
0113 3971337
# Commercial
08451772266
0845 1772266
# Mobile number (should not match)
07999888777
+447999888777
07999 888 777
+44 7999888777
`
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/