当前位置:网站首页>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(^_^)∠※!!!

边栏推荐
猜你喜欢

el-input文本域字数限制,超过显示变红并禁止输入

Multi picture alert ~ comparison of Huawei ECs and Alibaba cloud ECS

Dark horse programmer - software testing - stage 06 2-linux and database-01-08 Chapter 1 - description of the content of the Linux operating system stage, description of the basic format and common fo

SAP GUI 里的收藏夹事务码管理工具

切面条 C语言

转--深入LUA脚本语言,让你彻底明白调试原理

# CutefishOS系统~

配置筛选机
![[untitled]](/img/60/9a56e8b00c386779be13308515b24f.png)
[untitled]

内部字段分隔符
随机推荐
删除AWS绑定的信用卡账户
nn. Parameter] pytoch feature fusion adaptive weight setting (learnable weight use)
使用 EMQX Cloud 实现物联网设备一机一密验证
Ida dynamic debugging apk
Arlo's thinking after confusion
Fully annotated SSM framework construction
台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条
【图像分割】2021-SegFormer NeurIPS
功能测试报告的编写
The fixed assets management subsystem reports are divided into what categories and which accounts are included
internal field separator
104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
Electron学习(三)之简单交互操作
Fiori applications are shared through the enhancement of adaptation project
pytorch训练自己网络后可视化特征图谱的代码
Slope compensation
14年本科毕业,3个月转行软件测试月薪13.5k,32的岁我终于找对了方向
Single step debugging analysis of rxjs observable of operator
【无标题】
分享一个一年经历两次裁员的程序员的一些感触