当前位置:网站首页>【正则表达式】笔记
【正则表达式】笔记
2022-08-04 00:51:00 【昱浑】
- ^$
表示匹配从^到&之间的内容,用于开头结尾但可以省略, ^123&必须完全匹配123
范围:[] 、{} 、()
- []
约束内容。整个[]内只匹配一个字符 [abc123] 可以是abc123中的 一个 [a-zA-Z] 可以是任意一个字母;[^]: []内的^表示取反, [^a-zA-Z] 指不可以是字母 - {}
约束数量。单独[]只匹配一个字符.所以{}表示[]里的内容的个数, 如[]{3} 指定3个字符, []{3,5} 指定3个至5个, []{3,} 3至无数个。三种特殊数量: ?、*、 + - ()
表示组,一组内容视为一个整体,可以再对组做数量约束;
还可用于对正则中一部分数据分组取出;
分组的目的还可以重复应用,即后面内容必须和前面相等
字符
.点
表示可以匹配任意字符(除了换行) .{2,5} 匹配2至5个任意字符\d
匹配任何数字 等同于0-9 ; \D 等同^\d 不匹配任何字符\w
包括字母、数字、或下划线_\s
代表 [\r \n \t \f \v ]回车符、翻页符、空格等; \S 就是\s取反
数量
- ?
表示某个内容出现0至1次,等同于 {0,1} - *
表示某个内容出现0至无穷次 等同于{0,} (?和*都是对数量的约束,不指的是任意内容) - +
表示某个内容出现 1至无穷次 等同于{1,}
其他
- \
表示转义, 如.表示任意字符,但.表示必须匹配.这个字符
举例: 匹配是字符或数字开头的163邮箱: ^ [a-zA-Z0-9]\[email protected]%
- |
表示 或
()的其他用法
- ()
表示组,一组时一个整体,可以再对组做数量限制;还可用于对正则中一部分数据分组取出;分组的目的还可以重复应用,即后面内容必须和前面相等
^([a-zA-Z0-9]\w+)@163\.com%
^(?<first>[a-zA-Z0-9]\w+)@163\.com% 将邮箱@前内容取出并将分组命名为first
^\d\d\d\d% 表示四位数字
^(\d\d)\1% \1表示后面的内容引用前面的第一个分组 所以表示第三四位要等于第一二位
^(?<first>\d\d)\k<first>% 等同于^(\d\d)\1% ,在对组取名称情况下,要用\k<>引用
(?=str) 匹配并取出内容,且内容还要在str前的才行 如:cdx(?=ohh) cdxohh可以匹配,但cdxkkk就不行
(?!) 对上述取反, 表示不能在str前的才行
(?<=str) 匹配并取出内容,且内容还要在str后的才行 cdx(?<=ohh) ohhcdx
(?<!) 对上述取反, 表示不能在str后的才行
边栏推荐
猜你喜欢

typescript58-泛型类

WMS仓储管理系统能解决电子行业哪些仓库管理问题

How to find the cause of Fiori Launchpad routing errors by single-step debugging
![[Miscellaneous] How to install the specified font into the computer and then use the font in the Office software?](/img/15/23b0724f9c9672c61b91320f1b84d8.png)
[Miscellaneous] How to install the specified font into the computer and then use the font in the Office software?

Using matlab to solve the linear optimization problem based on matlab dynamic model of learning notes _11 】 【

typescript51 - basic use of generics

BGP实验(含MPLS)

What warehouse management problems can WMS warehouse management system solve in the electronics industry?

c语言分层理解(c语言指针(上))

typescript50 - type specification between cross types and interfaces
随机推荐
Jmeter cross-platform operation CSV files
nodeJs--async/await
跨域问题解决方式 代理服务器
fsdbDump用法
动态内存二
微服务的简单介绍
Read FastDFS in one article
Nanoprobes Alexa Fluor 488 FluoroNanogold 偶联物
The Beijing E-sports Metaverse Forum was successfully held
pcl点云数据 转化为 Eigen::Map
typescript56-泛型接口
DataBinding下的RecycleView适配器Adapter基类
Nanoprobes Mono- Sulfo -NHS-Nanogold的使用和应用
600MHz频段来了,它会是新的黄金频段吗?
带你造轮子,自定义一个随意拖拽可吸边的悬浮View组件
jmeter跨平台运行csv等文件
js中常用的几种遍历处理数据的方法梳理
LeetCode 19:删除链表的倒数第 N 个结点
C语言 函数递归
typescript48 - type compatibility between functions