package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^\w+(?:[_-][^\W_]+)*@(?![\d._-]+\.[^\W_]+$)[^\W_]+(?:[_-][^\W_]+)*\.[^\W_]{2,3}$`)
var str = `xxx@_domain.com
xxx@domain_.com
xxx@-domain.com
xxx@domain-.com
-xxx@domain.in
xxx@111.com
xxx@1and1.com
xxx@us.com
xxx@my-india.com
xxx@me2.com
xxx@tv.com
xxx@abc_efg.com
_muth@tamil.com
xx-u@my-india.commmmm
x-xx@1and1.com
xxx@_domain.com => invalid @ starts with _
xxx@domain_.com => invalid domain ends with _
xxx@-domain.com => invalid @ starts with - ( hypen)
xxx@domain-.com => invlaid domain ends with - (hypen)
-xxx@domain.in => invalid domain start with - (hypen)
xxx@111.com => invalid domain only contains numbers
xxx@1and1.com => valid domain contains both number and chars
xxx@us.com => valid
xxx@my-india.com => valid
xxx@me2.com => valid
xxx@tv.com =>
xxx@abc_efg.com => valid _ inside the chars
_muth@tamil.com => valid _ start with `
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/