当前位置:网站首页>Quantifiers of regular series
Quantifiers of regular series
2022-07-01 22:52:00 【Old__ L】
Catalog
Quantifiers indicate the number of characters or expressions to match .
1、x*
Put the previous item “x” matching 0 Times or more .
let reg = /bo*/g;
let str = "A ghost booooed";
str.match(reg); // ['boooo']
str = "A bird warbled";
str.match(reg); // ['b', 'b']
str = "A goat grunted";
str.match(reg); // null
2、x+
Put the previous item “x” matching 1 Times or more , Equivalent to {1,}
.
let reg = /bo+/g;
let str = "A ghost booooed";
str.match(reg); // ['boooo']
str = "A bird warbled";
str.match(reg); // null
str = "A goat grunted";
str.match(reg); // null
reg = /a+/g;
str = "caaaaaaandy";
str.match(reg); // ['aaaaaaa']
3、x?
Put the previous item “x” matching 0 or 1 Time .
If in any quantifier *
、+
、?
or {}
Then use ?
, Then the quantifier is non greedy ( The minimum number of matches ), Not acquiesced greedy ( The maximum number of matches ).
let reg = /bo?/g;
let str = "A ghost booooed";
str.match(reg); // ['bo']
str = "A bird warbled";
str.match(reg); // ['b', 'b']
str = "A goat grunted";
str.match(reg); // null
reg = /bo??/g;
str = "A ghost booooed";
str.match(reg); // ['b']
4、x{n}
among “n” Is a positive integer , With the previous item “x” Of n Secondary match .
let reg = /a{2}/g;
let str = "candy";
str.match(reg); // null
str = "caandy";
str.match(reg); // ['aa']
str = "caaandy";
str.match(reg); // ['aa']
5、x{n,}
among ,“n” Is a positive integer , With the previous item “x” Match at least “n” Time .
let reg = /a{2,}/g;
let str = "caaandy";
str.match(reg); // ['aaa']
6、x{n,m}
among n by 0 Or a positive integer ,m As a positive integer , And m > n, The previous one x Match at least n Times and at most m Time .
let reg = /a{2,4}/g;
let str = "caaaaaaaaaaandy";
str.match(reg); // ['aaaa', 'aaaa', 'aaa']
7、x*?
x+?
x??
x{n}?
x{n,}?
x{n,m}?
By default , image *
and +
Such quantifiers are “ Greedy ”, That means they try to match as many strings as possible . The character after the quantifier ?
Make quantifier “ Not greed ”: This means that once a match is found , It will stop .
let reg = /a{2,4}?/g;
let str = "caaaaaaaaaaandy";
str.match(reg); // ['aa', 'aa', 'aa', 'aa', 'aa']
Postscript
If you feel the article is not good
//(ㄒoㄒ)//
, Just leave a message in the comments , The author continues to improve ;o_O???
If you think the article is a little useful , You can praise the author ;\\*^o^*//
If you want to progress with the author , Sure Wechat scan QR code , Focus on the front-end old L;~~~///(^v^)\\\~~~
Thank you readers(^_^)∠※
!!!
边栏推荐
- Lc669. Prune binary search tree
- 内部字段分隔符
- Slope compensation
- LC669. 修剪二叉搜索树
- Wechat open platform scanning code login [easy to understand]
- 小红书Scheme跳转到指定页面
- 删除AWS绑定的信用卡账户
- Pytorch's code for visualizing feature maps after training its own network
- [daily training] 326 Power of 3
- [QT widget] encapsulates a simple thread management class
猜你喜欢
Configure filter
Appium自动化测试基础 — APPium安装(一)
Kubernetes create service access pod
陈天奇的机器学习编译课(免费)
台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条
The median salary of TSMC's global employees is about 460000, and the CEO is about 8.99 million; Apple raised the price of iPhone in Japan; VIM 9.0 release | geek headlines
Congratulations on the release of friends' new book (send welfare)
Redis configuration and optimization
Appium automated testing foundation - Supplement: introduction to desired capabilities parameters
转载csdn文章操作
随机推荐
人体姿态估计的热图变成坐标点的两种方案
Pytorch's code for visualizing feature maps after training its own network
Slope compensation
Tourism Management System
Object memory layout
104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
C#/VB. Net to add text / image watermarks to PDF documents
Pytorch nn.functional.unfold()的简单理解与用法
微信开放平台扫码登录[通俗易懂]
QStringList 的常规使用
ECMAScript 2022 正式发布,有你了解过的吗?
MySQL中对于索引的理解
Fiori applications are shared through the enhancement of adaptation project
2020-ViT ICLR
The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
Pytorch nn. functional. Simple understanding and usage of unfold()
rxjs Observable of 操作符的单步调试分析
Rust language - Introduction to Xiaobai 05
【图像分割】2021-SegFormer NeurIPS
nn. Parameter] pytoch feature fusion adaptive weight setting (learnable weight use)