import (
"fmt"
"regexp"
)
const text = `
my email is ccmouse@gmail.com@abc.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)
}
}
输出:
[ccmouse@gmail.com ccmouse gmail .com]
[abc@def.org abc def .org]
[kkk@qq.com kkk qq .com]
[ddd@abc.com.cn ddd abc .com.cn]
正则表达式解析电子邮件
本文展示了一段使用Go语言的代码,通过正则表达式从文本中匹配并提取电子邮件地址。具体展示了如何定义正则表达式模式,使用re包进行字符串匹配,以及如何遍历并打印所有匹配到的电子邮件地址。
3248

被折叠的 条评论
为什么被折叠?



