当前位置:网站首页>想要白嫖正则大全是吧?这一次给你个够!
想要白嫖正则大全是吧?这一次给你个够!
2022-07-25 11:53:00 【前端技术栈】

点赞再看,养成好习惯!收藏学会,卷王也不累~
另外 1 个小 tips,对正则阅读有障碍的同学可以借助这个网站 jex.im/regulex/,将正则可视化,从此爱上读正则!
比如:校验邮箱的正则:
^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
可视化后,直接看图说话,小白都会,真滴 tql !!
好了,冲了!
号码相关
手机号(以 1 开头):/^(?:(?:\+|00)86)?1\d{10}$/ 手机号(以 13 至19 开头):/^(?:(?:\+|00)86)?1[3-9]\d{9}$/ 手机号(以工信部公布的手机号段开头):/^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/ 国内固话号码:/\d{3}-\d{8}|\d{4}-\d{7}/ 邮箱号:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/ 邮政编码:/[1-9]\d{5}(?!\d)/ 身份证号:/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/ 银行卡号(公、私账户):/^[1-9]\d{9,29}$/ 车牌号:/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/ QQ 号:/^[1-9][0-9]{4,10}$/ 微信号:/^[a-zA-Z][-_a-zA-Z0-9]{5,19}$/ 版本号( x.y.z ):/^\d+(?:\.\d+){2}$/ 合法账号1(字母开头,5-16位,允许字母数字下划线):/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/ 合法账号2(4-16位,允许字母,数字,下划线,减号):/^[a-zA-Z0-9_-]{4,16}$/ 强密码1(必须包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间):/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$/ 强密码2(必须包含字母、数字、特殊字符:**@#$%^& `~()-+=* ): /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\[email protected]#$%^&* ~()-+=]+$)(?![a-z0-9]+$)(?![a-z\\[email protected]#$%^& *~()-+=]+$)(?![0-9\[email protected]#$%^&* ~()-+=]+$)[a-zA-Z0-9\\[email protected]#$%^&*~()-+=]/ 网址:/^(((ht|f)tps?):\/\/)?(^[email protected]#$%^&*?.\s-?\.)+[a-z]{2,6}\/?/ 网址带端口号:/^((ht|f)tps?:\/\/)?[\w-]+(\.[\w-]+)+:\d{1,5}\/?$/ ip-v4:/\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b/ ip-v6:/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/
数字相关
只有数字:/^[0-9]*$/ 或 /^\d{1,}$/ 整数:/^-?[0-9]\d*$/ 正整数:/^\+?[1-9]\d*$/ 非正整数:/^-[1-9]\d*|0$/ 负整数:/^-[1-9]\d*$/ 非负整数:/^\d+$/ 浮点数:/^(-?\d+)(\.\d+)?$/ 正浮点数:/^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$/ 负浮点数:/^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)/ 小数:/^-?\d+\.\d+$/ 正数/负数/小数:/^(\-|\+)?\d+(\.\d+)?$/ 正实数保留小数点后 2 位:/^[0-9]+(.[0-9]{2})?$/ 正实数保留小数点后 1 到 3 位:/^[0-9]+(.[0-9]{1,3})?$/ n 位数字:/^\d{n}$/ 至少 n 位数字:/^\d{n,}$/ m 至 n 位的数字:/^\d{m,n}$/ 数字和字母至少包含其一:/^[A-Za-z0-9]+$/ 必须包含数字和字母:/^(?=.*[a-zA-Z])(?=.*\d).+$/ md5 值 :/^([a-f\d]{32}|[A-F\d]{32})$/ base64 值:/^\s*data:(?:[a-z]+\/[a-z0-9-+.]+(?:;[a-z-]+=[a-z0-9-]+)?)?(?:;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s]*?)\s*$/i
字符相关
m 至 n 位的字符:/^.{3,20}$/ 英文字母字符:/^[A-Za-z]+$/ 大写英文字母字符:/^[A-Z]+$/ 小写英文字母字符:/^[a-z]+$/ 汉字:/^[\u4e00-\u9fa5]{0,}$/ 全角符号:/[\uFF00-\uFFFF]/ 半角符号:/[\u0000-\u00FF]/ 汉字、英文、数字、下划线至少其一:/^[\u4E00-\u9FA5A-Za-z0-9_]+$/ 不包含字符 “~” :/[^~\x22]+/ 字符连续重复:/(.)\1+/
时间相关
24小时制时间(HH:mm:ss):/^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/ 12小时制时间(hh:mm:ss):/^(?:1[0-2]|0?[1-9]):[0-5]\d:[0-5]\d$/ 24小时制时间(HHmmss):/([0-1]?[0-9]|2[0-3])([0-5][0-9])([0-5][0-9])$/ 日期1(yyyy-MM-dd,如 2222-01-01,年份必为4位):/^\d{4}-\d{1,2}-\d{1,2}/ 日期2(如 333-01-01,年份可小于4位):/^\d{1,4}(-)(1[0-2]|0?[1-9])\1(0?[1-9]|[1-2]\d|30|31)$/ 日期3(yyyyMMdd,如 20220202):/^((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))0229))$/ 日期+时间1(YYYYMMDD HH:mm:ss):/^\d{4}([/:-\S])(1[0-2]|0?[1-9])\1(0?[1-9]|[1-2]\d|30|31) (?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/ 日期+时间2: /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/ 一年 12 个月((01~09 或 1~12)):/^(0?[1-9]|1[0-2])$/ 一个月 31 天(01~09 或 1~31):/^((0?[1-9])|((1|2)[0-9])|30|31)$/ 有 31 天的月份:/^(0?[13578]|1[02])$/ 有 30 天月的份:/(0[469]|11)-(0[1-9]|[12][0-9]|30)/ 2 月 28 天("02-28"):/^02-(0[1-9]|[1][0-9]|2[0-8])$/ 闰年:/^(((19|20)([13579][26]|[2468][048]|0[48]))|(2000))$/ 闰年 2 月(比如 2008-02-01):/^(((19|20)([13579][26]|[2468][048]|0[48]))|(2000))-0?2-(0?[1-9]|[12]\d)$/ 日期(包括闰年、大小月的判断):/((((19|20)\d{2})-(0?(1|[3-9])|1[012])-(0?[1-9]|[12]\d|30))|(((19|20)\d{2})-(0?[13578]|1[02])-31)|(((19|20)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))-0?2-29))$/ 年份区间-年(比如 19 年至 20 年):/^((19|20)\d{2})$/ 年份区间-年月(比如 1999-01):/^((((19|20)\d{2})-(0?[13-9]|1[012]))|(((19|20)\d{2})-(0?[13578]|1[02]))|(((19|20)\d{2})-0?2)|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))-0?2))$/ 年份区间-年月日(比如 1999-01-01):/^((((19|20)\d{2})-(0?[13-9]|1[012])-(0?[1-9]|[12]\d|30))|(((19|20)\d{2})-(0?[13578]|1[02])-31)|(((19|20)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))-0?2-29))$/.test('2021-02-21')$/ 年份区间-年月日(间隔符号可为 - / 或空):/^(?:(?:1[6-9]|[2-9][0-9])[0-9]{2}([-/.]?)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:(?:1[6-9]|[2-9][0-9])(?:0[48]|[2468][048]|[13579][26])|(?:16|[2468][048]|[3579][26])00)([-/.]?)0?2\2(?:29))$/
编程相关
16进制颜色:/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/ 提取网页颜色代码:/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/ 视频链接地址:/^https?:\/\/(.+\/)+.+(\.(swf|avi|flv|mpg|rm|mov|wav|asf|3gp|mkv|rmvb|mp4))$/i 图片链接地址:/^https?:\/\/(.+\/)+.+(\.(gif|png|jpg|jpeg|webp|svg|psd|bmp|tif))$/i mac 地址:/^((([a-f0-9]{2}:){5})|(([a-f0-9]{2}-){5}))[a-f0-9]{2}$/i 子网掩码:/^((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))$/ 文件扩展名效验:/^([a-zA-Z]\\:|\\\\)\\\\([^\\\\]+\\\\)*[^\\/:*?"<>|]+\\.txt(l)?$/ java包名(x.x.x):/^([a-zA-Z_]\w*)+([.][a-zA-Z_]\w*)+$/ xml文件:/^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$/ html 注释:/<!--[\s\S]*?-->/g html 标签1:/<(\w+)[^>]*>(.*?<\/\1>)?/ html 标签2:/<(\S*?)[^>]*>.*?</\1>|<.*? />/ 首尾空白字符:/^\s*|\s*$/ 查找CSS属性:/^\\s*[a-zA-Z\\-]+\\s*[:]{1}\\s[a-zA-Z0-9\\s.#]+[;]{1}/ 提取页面超链接:/(<a\\s*(?!.*\\brel=)[^>]*)(href="https?:\\/\\/)((?!(?:(?:www\\.)?'.implode('|(?:www\\.)?', $follow_list).'))[^" rel="external nofollow" ]+)"((?!.*\\brel=)[^>]*)(?:[^>]*)>/ 提取网页图片:/\\< *[img][^\\\\>]*[src] *= *[\\"\\']{0,1}([^\\"\\'\\ >]*)/ 迅雷链接:/^thunder:\/\/[a-zA-Z0-9]+=$/ ed2k链接:/^ed2k:\/\/|file|.+|\/$/ linux"文件"路径:/^\/(\w+\/)+\w+\.\w+$/ window下"文件"路径:/^[a-zA-Z]:\\(?:\w+\\)*\w+\.\w+$/
生活相关
金额(宽松,可为负、首位可为0,支持千分位分隔):/^-?\d+(,\d{3})*(\.\d{1,2})?$/ 金额(大于 0 ,两位小数):/(^[1-9]{1}[0-9]*$)|(^[0-9]*\.[0-9]{2}$)/ 金额(严格,不为负、小数点后最多两位,首位不为0):/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/ 护照:/(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/ 香港身份证:/^[a-zA-Z]\d{6}\([\dA]\)$/ 澳门身份证:/^[1|5|7]\d{6}\(\d\)$/ 湾湾身份证:/^[a-zA-Z][0-9]{9}$/ 股票代码:/^(s[hz]|S[HZ])(000[\d]{3}|002[\d]{3}|300[\d]{3}|600[\d]{3}|60[\d]{4})$/ 不含 abc 的单词:/\b((?!abc)\w)+\b/
程序员面试题库分享
1、前端面试题库 (面试必备) 推荐:*****
地址:前端面试题库
边栏推荐
- 2.1.2 application of machine learning
- A method to prevent SYN flooding attacks -- syn cookies
- Median (two point answer + two point search)
- PyTorch项目实战—FashionMNIST时装分类
- Ansible
- 微软Azure和易观分析联合发布《企业级云原生平台驱动数字化转型》报告
- Microsoft azure and Analysys jointly released the report "Enterprise Cloud native platform driven digital transformation"
- mysql实现一张表数据插入另一张表
- Eureka使用记录
- [shutter -- layout] stacked layout (stack and positioned)
猜你喜欢

Musk's "eternal soul": half hype, half flicker

More accurate and efficient segmentation of organs-at-risk in radiotherapy with Convolutional Neural

Dr. water 2

Eureka注册中心开启密码认证-记录
软件测试流程包括哪些内容?测试方法有哪些?

Fiddler packet capturing app

Build a series of vision transformer practices, and finally meet, Timm library!

Pytorch visualization

Pytorch project practice - fashionmnist fashion classification

Introduction to the scratch crawler framework
随机推荐
【9】 Coordinate grid addition and adjustment
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the dot strip chart, set the palette parameter to configure the color of data points at different levels,
Cmake learning notes (II) generation and use of Library
论文解读(MaskGAE)《MaskGAE: Masked Graph Modeling Meets Graph Autoencoders》
通过Referer请求头实现防盗链
Hystrix使用
Atomic atomic class
mysql实现一张表数据插入另一张表
技术管理杂谈
如何从远程访问 DMS数据库?IP地址是啥?用户名是啥?
Implement anti-theft chain through referer request header
Create directories and subdirectories circularly
Fiddler抓包APP
2022.07.24(LC_6125_相等行列对)
keepalived实现mysql的高可用
Median (two point answer + two point search)
How to access DMS database remotely? What is the IP address? What is the user name?
If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing
Musk's "eternal soul": half hype, half flicker
Monit installation and use