golang常用正则表达式集合插件库commonregex的使用
Golang常用正则表达式集合插件库commonregex的使用
CommonRegex是一个Go语言常用的正则表达式集合库,提供了多种常见模式的匹配功能。
安装
go get github.com/mingrammer/commonregex
使用示例
import (
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)
// ['Jan 9th 2012']
timeList := cregex.Time(text)
// ['5:00PM', '4:00']
linkList := cregex.Links(text)
// ['www.linkedin.com', 'harold.smith@gmail.com']
phoneList := cregex.PhonesWithExts(text)
// ['(519)-236-2723x341']
emailList := cregex.Emails(text)
// ['harold.smith@gmail.com']
}
功能特性
CommonRegex提供了以下常见模式的匹配功能:
- 日期(Date)
- 时间(Time)
- 电话号码(Phone)
- 带分机号的电话号码(Phones with exts)
- 链接(Link)
- 电子邮件(Email)
- IPv4地址
- IPv6地址
- IP地址(IPv4/IPv6)
- 非知名端口号(Ports without well-known)
- 价格(Price)
- 十六进制颜色值(Hex color)
- 信用卡号(Credit card)
- VISA信用卡号
- 万事达信用卡号(MC credit card)
- ISBN 10/13
- BTC地址
- 街道地址(Street address)
- 邮政编码(Zip code)
- 邮政信箱(Po box)
- 社会安全号码(SSN)
- MD5哈希值
- SHA1哈希值
- SHA256哈希值
- GUID
- MAC地址
- IBAN银行账号
- Git仓库地址
许可证
该项目采用MIT许可证。
更多关于golang常用正则表达式集合插件库commonregex的使用的实战教程也可以访问 https://www.itying.com/category-94-b0.html
1 回复