当前位置:网站首页>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
边栏推荐
- SSM framework series - data source configuration day2-1
- SSM框架系列——数据源配置day2-1
- Unable to create servlet under SRC subfile of idea
- 将新增和编辑的数据同步更新到列表
- Record some NPM related problems (messy records)
- Markdown grammar learning
- 云原生KubeSphere部署Redis
- CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
- World Book Day: I'd like to recommend these books
- 世界读书日:我想推荐这几本书
猜你喜欢
Sort out several uses of network IP agent
NPDP | how can product managers not be excluded by programmers?
Introduction to kubernetes
Free and open source agricultural Internet of things cloud platform (version: 3.0.1)
Van uploader upload picture implementation process, using native input to upload pictures
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
【蓝桥杯】4月17日省赛刷题训练(前3道题)
22. 括号生成
Teach you to quickly develop a werewolf killing wechat applet (with source code)
Record some NPM related problems (messy records)
随机推荐
Web17 -- use of El and JSTL
Servlet监听器&过滤器介绍
22. 括号生成
Homomorphic encryption technology learning
leetcode:437. 路径总和 III【dfs 选还是不选?】
[daily question] chessboard question
【csnote】ER图
leetcode-791. 自定义字符串排序
解锁OpenHarmony技术日!年度盛会,即将揭幕!
There is no need to crack the markdown editing tool typora
甲辰篇 創世紀《「內元宇宙」聯載》
STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
8 websites that should be known for product development to enhance work experience
Kubernetes 入門教程
Introduction to kubernetes
If you were a golang interviewer, what questions would you ask?
Analysis of InnoDB execution process in MySQL
php生成json处理中文
Baserecyclerviewadapterhelper realizes pull-down refresh and pull-up loading
Recommended website for drawing result map