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

边栏推荐
猜你喜欢

MySQL5.7 设置密码策略(等保三级密码改造)

激发新动能 多地发力数字经济

使用 Three.js 实现'雪糕'地球,让地球也凉爽一夏

转--原来gdb的底层调试原理这么简单

多图预警~ 华为 ECS 与 阿里云 ECS 对比实战

The fixed assets management subsystem reports are divided into what categories and which accounts are included

# CutefishOS系统~

元宇宙可能成为互联网发展的新方向

内部字段分隔符

Share some feelings of a programmer who has experienced layoffs twice a year
随机推荐
恶意软件反向关闭EDR的原理、测试和反制思考
Rust语言——小小白的入门学习05
聊一聊Zabbix都监控哪些参数
Mysql database detailed learning tutorial
How to write a performance test plan
Slope compensation
Lc669. Prune binary search tree
Appium automation test foundation - appium installation (I)
Selection of all-optical technology in the park - Part 2
MySQL5.7 设置密码策略(等保三级密码改造)
Intelligent computing architecture design of Internet
【QT小作】封装一个简单的线程管理类
阿洛迷茫后的思考
转--深入LUA脚本语言,让你彻底明白调试原理
vSphere+、vSAN+来了!VMware 混合云聚焦:原生、快速迁移、混合负载
ECMAScript 2022 正式发布,有你了解过的吗?
Efficiency improvement - encourage personalized container development environment
Kubernetes create service access pod
Compensation des créneaux horaires
[untitled]