GO -- 正则表达式

str := "880218end"
	match, _ := regexp.MatchString("\\d{16}", str) //六位连续的数字
	fmt.Println(match)    //输出true
	reg := regexp.MustCompile("\\d{6}")
	//返回str中第一个匹配reg的字符串
	data := reg.Find([]byte(str))
	fmt.Println(string(data))  //880218
	//go语言正则表达式判断是否为汉字
	matchChinese, _ := regexp.Match("[\u4e00-\u9fa5]", []byte("经度"))
	fmt.Println(matchChinese)       //输出true
	//go语言正则表达式判断是否含有字符(大小写)
	matchChar, _ := regexp.Match("[a-zA-Z]", []byte("av132"))
	fmt.Println(matchChar)         //输出false
	//go语言正则表达式判断是否含有以数字开头,不是为true
	matchDigit, _ := regexp.Match(`[^\d]`, []byte("as132"))
	fmt.Println(matchDigit)         //输出true
	//go语言正则表达式判断是否含有为IP地址
	ip := "10.32.12.01"
	pattern := "[\\d]+\\.[\\d]+\\.[\\d]+\\.[\\d]+"
	matchIp, _ := regexp.MatchString(pattern, ip)
	fmt.Println(matchIp)          //输出true
	//go语言正则表达式判断是否包含某些字段
	id := "id=123;dfg"
	reg = regexp.MustCompile("id=[\\d]+")
	MEId := reg.FindString(id)
	fmt.Println(MEId)         //输出id=123
	// 判断是否是个单词
	pattern = "^[A-Z]+$|(^[A-Z]?[a-z]+)$"
	char := "mAfeng"
	match, _ =  regexp.Match(pattern, []byte(char))
	fmt.Println(match)

 

转载于:https://www.cnblogs.com/mafeng/p/10364787.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值