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

边栏推荐
- 转--深入LUA脚本语言,让你彻底明白调试原理
- Electron学习(三)之简单交互操作
- Hide the creation and use of users
- 【图像分割】2021-SegFormer NeurIPS
- 转--拿来即用:分享一个检查内存泄漏的小工具
- Detailed explanation of common configurations in redis configuration file [easy to understand]
- 台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条
- 【c语言】malloc函数详解[通俗易懂]
- 效率提升 - 鼓捣个性化容器开发环境
- Selection of all-optical technology in the park - Part 2
猜你喜欢

104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目

“信任机器”为发展赋能

Sogou wechat app reverse (II) so layer

map容器

Ida dynamic debugging apk

Appium自动化测试基础 — 补充:Desired Capabilities参数介绍

Appium automation test foundation - appium installation (I)

Mysql5.7 set password policy (etc. three-level password transformation)

FFMpeg学习笔记

Slope compensation
随机推荐
Electron学习(三)之简单交互操作
[C language] detailed explanation of malloc function [easy to understand]
Origin2018安装教程「建议收藏」
Share some feelings of a programmer who has experienced layoffs twice a year
Sogou wechat app reverse (II) so layer
Multi picture alert ~ comparison of Huawei ECs and Alibaba cloud ECS
JVM有哪些类加载机制?
104. SAP ui5 table control supports multi select and how to select multiple table row items at a time with code
Delete AWS bound credit card account
Configure filter
聊一聊Zabbix都监控哪些参数
Rust language - Introduction to Xiaobai 05
Understanding of indexes in MySQL
2020-ViT ICLR
分享一个一年经历两次裁员的程序员的一些感触
Fiori 应用通过 Adaptation Project 的增强方式分享
元宇宙可能成为互联网发展的新方向
【日常训练】326. 3 的幂
cvpr2022 human pose estiamtion
Redis configuration and optimization