GO 正则匹配邮箱地址

180it 2020-10-30 PM 2361℃ 0条

package main

import (

"fmt"
"regexp"

)

const text = `
My email is 8899666@qq.com
email1 is abc@def.org
email2 is kkk@qq.com
email3 is ddd@abc.com.cn
`
func main() {

//确定要寻找的目标及返回需要的字符段
re  := regexp.MustCompile(`([a-zA-Z0-9]+)@([a-zA-Z0-9]+)(\.[a-zA-Z0-9.]+)`)
//返回二维数组 函数的作用是得到字符段并按要求返回需要的单个字符串
match := re.FindAllStringSubmatch(text,-1)
//循环打印每一段字符
for _, m := range match{
    fmt.Println(m)
}

}

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

GO 正则匹配邮箱地址