package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(?=.{10,15}$)(?=.*(?:.*\d){10}.*$)([\(\)\p{Zs}.-]*[0-9]{3}[\(\)\p{Zs}.-]*[0-9]{3}[\(\)\p{Zs}.-]*[0-9]{4})$`)
var str = `(501) 555 1234
(501)-555.1234
501-555-1234
501.555.1234
501 555 1234
501) 343-2233
(501 343-2233
(501. 343-2233
5013432233
800-..555-1234
(.8005551234
*-(.8005551234
501*555-1234
-(.80055512 41
501_555_1234
555-1234
800-...........555-1234
013432233
1. The string must be 10-15 total characters in length.
2. Must contain exactly 10 digits within string.
3. Can contain "(", ")" , " ", ".", or "-" delimiters within the string.
4. It doesn't matter how many delimiters are grouped as long as numbers are grouped in {3}{3}{4}.`
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/