当前位置:网站首页>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
边栏推荐
- 梳理网络IP代理的几大用途
- 风尚云网学习-input属性总结
- 航芯技术分享 | ACM32 MCU安全特性概述
- Ad20 supplementary note 3 - shortcut key + continuous update
- Introducing vant components on demand
- Realize several "Postures" in which a box is horizontally and vertically centered in the parent box
- STM32 control stepper motor (ULN2003 + 28byj)
- Plato farm - a game of farm metauniverse with Plato as the goal
- STM32工程移植:不同型号芯片工程之间的移植:ZE到C8
- 31. 下一个排列
猜你喜欢

【csnote】ER图

Idea的src子文件下无法创建servlet
![Packet capturing and sorting -- TCP protocol [8]](/img/ae/4957a997af725a1bf3f61cb24fc717.png)
Packet capturing and sorting -- TCP protocol [8]

Free and open source intelligent charging pile SaaS cloud platform of Internet of things

mysql中 innoDB执行过程分析

Object. The disorder of key value array after keys

世界读书日:我想推荐这几本书

Zigbee之CC2530最小系统及寄存器配置(1)

NPDP | how can product managers not be excluded by programmers?

box-sizing
随机推荐
How to prevent the website from being hacked and tampered with
BUUCTF WEB [BUUCTF 2018]Online Tool
Introduction to kubernetes
只是不断地建构平台,不断地收拢流量,并不能够做好产业互联网
Synchronously update the newly added and edited data to the list
leetcode:437. Path sum III [DFS selected or not selected?]
31. 下一个排列
Markdown grammar learning
Object. The disorder of key value array after keys
98. Error s.e.errormvcautoconfiguration $staticview reported by freemaker framework: cannot render error page for request
C, calculation code of parameter points of two-dimensional Bezier curve
如何防止网站被黑客入侵篡改
Introduction to servlet listener & filter
[vulnhub range] - DC2
Plato farm - a game of farm metauniverse with Plato as the goal
At instruction of nbiot
There is no need to crack the markdown editing tool typora
Pytorch: a pit about the implementation of gradreverselayer
进程虚拟地址空间区域划分
PC starts multiple wechat at one time