当前位置:网站首页>Golang realizes regular matching: the password contains at least one digit, letter and special character, and the length is 8-16
Golang realizes regular matching: the password contains at least one digit, letter and special character, and the length is 8-16
2022-04-23 12:56:00 【Play ha ha 527】
golang The regular matching password contains at least one digit , Letters and special characters , And length 8-16
Preface
because golang Regular matching rules such as pre check are not supported ,regex The package does not support ?= And so on , Complex regular matching is difficult to achieve , Open source packages are available regex2
One 、 Installation package go get github.com/dlclark/regexp2
Two 、 Use
The code is as follows ( Example ):
func matchStr(str string) string {
expr := `^(?![0-9a-zA-Z]+$)(?![a-zA-Z!@#$%^&*]+$)(?![0-9!@#$%^&*]+$)[0-9A-Za-z!@#$%^&*]{8,16}$`
reg, _ := regexp2.Compile(expr, 0)
m, _ := reg.FindStringMatch(str)
if m != nil {
res:= m.String()
return res
}
return " The password contains at least one digit , Letters and special characters , And length 8-16"
}
3、 ... and 、 explain
“^(?![0-9a-zA-Z]+$)(?![a-zA-Z!@#$%^&*]+$)(?![0-9!@#$%^&*]+$)[0-9A-Za-z!@#$%^&*]{8,16}$” in :(?![0-9a-zA-Z]+$) Indicates a match followed by a non number , Non alphabetic characters
(?![a-zA-Z!@#$%^&*]+$) Indicates a match followed by a non letter , Non special characters
(?![0-9!@#$%^&*]+$) Indicates a match followed by a non number , Non special characters
[0-9A-Za-z!@#$%^&*]{8,16} Length 8-16, It can be any number , Letters and the special characters they contain
版权声明
本文为[Play ha ha 527]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230615231222.html
边栏推荐
猜你喜欢
Zigbee之CC2530最小系统及寄存器配置(1)
22. 括号生成
0基础可以考CPDA数据分析师证书吗
31. Next arrangement
【csnote】ER图
Labels and paths
航芯技术分享 | ACM32 MCU安全特性概述
4. DRF permission & access frequency & filtering & sorting
解决disagrees about version of symbol device_create
Free and open source intelligent charging pile SaaS cloud platform of Internet of things
随机推荐
SSM framework series - data source configuration day2-1
梳理網絡IP代理的幾大用途
Web17 -- use of El and JSTL
Free and open source charging pile Internet of things cloud platform
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
Labels and paths
CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
Softbank vision fund entered the Web3 security industry and led a new round of investment of US $60 million in certik
Embrace the new blue ocean of machine vision and hope to open a new "Ji" encounter for the development of digital economy
洛谷P5540 [BalkanOI2011] timeismoney | 最小乘积生成树 题解
Wonderful review | the sixth issue of "source" - open source economy and industrial investment
Synchronously update the newly added and edited data to the list
mysql8安装
0基础可以考CPDA数据分析师证书吗
拥抱机器视觉新蓝海,冀为好望开启数字经济发展新“冀”遇
21 days learning mongodb notes
数据库中的日期时间类型
leetcode-791. Custom string sorting
How to click an object to play an animation
[vulnhub range] - DC2