github.com/pubgo/regex
github.com/mingrammer/commonregex
https://darjun.github.io/2020/09/05/godailylib/commonregex
它提供了这些作为获取与特定模式对应的匹配字符串的简单函数。
- 日期
- 时间
- 电话号码
- 超链接
- 邮件地址
- IPv4/IPv6/IP 地址
- 价格
- 十六进制颜色值
- 信用卡卡号
- 10/13 位 ISBN
- 邮政编码
- MD5
- SHA1
- SHA256
- GUID,全局唯一标识
- Git 仓库地址
package main
import (
"fmt"
cregex "github.com/mingrammer/commonregex"
)
func main() {
text := `John, please get that article on www.linkedin.com to me by 5:00PM on Jan 9th 2012. 4:00 would be ideal, actually. If you have any questions, You can reach me at (519)-236-2723x341 or get in touch with my associate at harold.smith@gmail.com`
dateList := cregex.Date(text)
timeList := cregex.Time(text)
linkList := cregex.Links(text)
phoneList := cregex.PhonesWithExts(text)
emailList := cregex.Emails(text)
fmt.Println("date list:", dateList)
fmt.Println("time list:", timeList)
fmt.Println("link list:", linkList)
fmt.Println("phone list:", phoneList)
fmt.Println("email list:", emailList)
}