当前位置:网站首页>正则匹配以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))
边栏推荐
- Golang etcdv3 reports an error. The attribute in grpc does not exist
- C语言指针(特别篇)
- 端口复用和重映像
- H3C VXLAN配置
- 硬核分享:硬件工程师常用工具包
- What are the suggestions for PMP candidates?
- Run can start normally, and debug doesn't start or report an error, which seems to be stuck
- Cesium does not support 4490 problem solution and cesium modified source code packaging scheme
- When inputting an expression in the input box, an error is reported: incorrect string value:'\xf0\x9f... ' for column 'XXX' at row 1
- Summary of PMP learning materials
猜你喜欢

面板显示技术:LCD与OLED

UnityShader入门精要个人总结--基础篇(一)

PMP Exam details after the release of the new exam outline

PMP certificate preparation experience sharing

How to use Arthas to view class variable values

C语言指针(特别篇)

2020 year end summary

Locust performance test 2 (interface request)

Register address name mapping

Serial port experiment - simple data sending and receiving
随机推荐
Summary of PMP learning materials
Port occupation troubleshooting
C language pointer (Part 2)
模拟卷Leetcode【普通】1557. 可以到达所有点的最少点数目
OpenGL 3D graphics rendering
串口實驗——簡單數據收發
STM32 clock system
Led analog and digital dimming
Hard core sharing: a common toolkit for hardware engineers
H3C vxlan configuration
Reflections on the way of enterprise IT architecture transformation (Alibaba's China Taiwan strategic thought and architecture practice)
PMP experience learning and sharing process
硬件大熊原创合集(2022/05更新)
JVM 垃圾回收 详细学习笔记(二)
C语言指针(习题篇)
模拟卷Leetcode【普通】1567. 乘积为正数的最长子数组长度
What are the conditions for applying for NPDP?
How can I apply for a PMP certificate?
[chaosblade: node disk filling, killing the specified process on the node, suspending the specified process on the node]
端口复用和重映像