package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`\([1-9]\d\)\s9?\d{4}-\d{4}`)
var str = `(11) 1111-1111 - fixo válido
(11) 11111-1111 - celular inválido
(11) 91111-1111 - celular válido
(11) 01111-1111 - celular inv álido
(01) 91111-1111 - celular válido
`
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/