当前位置:网站首页>正则匹配以XXX开头的,XXX结束的
正则匹配以XXX开头的,XXX结束的
2022-07-07 06:30:00 【大锤爱编程】
目录
前言
正则匹配是描述某种规则的表达式,能够很大程度提升字符串摘取和字符串匹配的工作效率。

一、正则匹配是什么?
正则表达式(英语:Regular Expression,常简写为regex、regexp或RE),又称正则表示式、正则表示法、规则表达式、常规表示法是计算机科学的一个概念。正则表达式使用单个字符串来描述、匹配一系列匹配某个句法规则的字符串。比如Linux系统中的Grep命令
二、正则匹配语法练习
1、全字符串匹配
全字符串匹配就是素正则表达式,就是一个简单的查找功能,比如查询was,test这些英文单次而已。
正则表达式:was
2、匹配XXX开始、XXX结束、XXX
在正则表达式的语法中有^开头的,这表明以XXX来作为开头,下面的这个例子就是匹配以sh作为开头的单词~
正则表达式:^sh在正则表达式的语法中有$结束的,这表明以XXX来作为开头,下面的这个例子就是匹配以lls作为结束的单词~
正则表达式:lls$
总结
今天简单介绍了正则匹配当中的以XXX开始和以XXX结尾的语法,后面会找一些重头戏来详细剖析。
最后的最后,放一点儿正则表达式福利:
去掉左右空格:
str.replace(/(^\s*)|(\s*$)/g, '')去掉所有空格:
str.replace(/\s+/g, '')密码需由8位以上大写字母、小写字母、数字及特殊符号组成:
/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!.,@$%^&*-]).{8,}$/Email地址:
^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$域名:[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?
InternetURL:[a-zA-z]+://[
^s]* 或^http://([w-]+.)+[w-]+(/[w-./?%&=]*)?$`手机号码:
^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])d{8}$电话号码(“XXX-XXXXXXX”、”XXXX-XXXXXXXX”、”XXX-XXXXXXX”、”XXX-XXXXXXXX”、”XXXXXXX”和”XXXXXXXX):
^((d{3,4}-)|d{3.4}-)?d{7,8}$国内电话号码
(0511-4405222、021-87888822):d{3}-d{8}|d{4}-d{7}身份证号(15位、18位数字):
^d{15}|d{18}$短身份证号码(数字、字母x结尾):
^([0-9]){7,18}(x|X)?$或^d{8,18}|[0-9x]{8,18}|[0-9X]{8,18}?$帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):
^[a-zA-Z][a-zA-Z0-9_]{4,15}$密码(以字母开头,长度在6~18之间,只能包含字母、数字和下划线):
^[a-zA-Z]w{5,17}$强密码(必须包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间):
^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$日期格式:
^d{4}-d{1,2}-d{1,2}一年的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)$xml文件:^([a-zA-Z]+-?)+[a-zA-Z0-9]+\.[x|X][m|M][l|L]$空白行的正则表达式:
s*(可以用来删除空白行)HTML标记的正则表达式:
<(S*?)[`^>]*>.*?</>|<.*? />(网上流传的版本太糟糕,上面这个也仅仅能部分,对于复杂的嵌套标记依旧无能为力)首尾空白字符的正则表达式:
^s*|s*$或(^s*)|(s*$) (可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式)腾讯QQ号:
[1-9][0-9]{4,}(腾讯QQ号从10000开始)中国邮政编码:
[1-9]d{5}(?!d)(中国邮政编码为6位数字)IP地址:
((?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d))
边栏推荐
- Postman interface test (II. Set global variables \ sets)
- Goldbach conjecture C language
- Storage of data in memory
- 5A summary: seven stages of PMP learning
- C language pointer (exercises)
- Detailed learning notes of JVM memory structure (I)
- JVM 垃圾回收 详细学习笔记(二)
- go mod module declares its path as: gtihub. com/xxx-xx but was required as:xx-xx
- Expérience de port série - simple réception et réception de données
- C language pointer (Part 1)
猜你喜欢

2022-07-06 Unity核心9——3D动画

Cesium does not support 4490 problem solution and cesium modified source code packaging scheme

What is the use of PMP certificate?

C语言指针(下篇)
![Pytest+request+allure+excel interface automatic construction from 0 to 1 [familiar with framework structure]](/img/33/9fde4bce4866b988dd2393a665a48c.jpg)
Pytest+request+allure+excel interface automatic construction from 0 to 1 [familiar with framework structure]

JVM 内存结构 详细学习笔记(一)

面板显示技术:LCD与OLED

Implementation of corner badge of Youmeng message push

STM32的时钟系统

Postman data driven
随机推荐
Several methods of calculating the average value of two numbers
PMP Exam Preparation experience, seek common ground while reserving differences, and successfully pass the exam
Simulation volume leetcode [general] 1557 The minimum number of points that can reach all points
What are the suggestions for PMP candidates?
2022-07-06 unity core 9 - 3D animation
Led analog and digital dimming
Systick滴答定时器
Golang etcdv3 reports an error. The attribute in grpc does not exist
OpenGL 3D graphics rendering
C language pointer (Part 2)
Register address name mapping
OpenGL三维图形绘制
Cesium load vector data
E-commerce campaign Guide
【SVN】SVN是什么?怎么使用?
C language pointer (special article)
Cmake command line use
PMP experience learning and sharing process
模拟卷Leetcode【普通】1609. 奇偶树
Ppt template and material download website (pure dry goods, recommended Collection)