当前位置:网站首页>Assertions of regular series
Assertions of regular series
2022-06-30 13:16:00 【Old__ L】
Catalog
One of the components of an assertion is a boundary . For the text 、 Word or pattern , Boundaries can be used to indicate their starting or ending parts ( Such as forward assertion , Backward assertions and conditional expressions ).
1、 Boundary class assertion
1.1、^
Match the beginning of the input . If the multiline mode is set to true,^ stay After newline It can also match immediately .
let reg = /^1[3-9]\d{9}/gm;
let str = "25000000000";
reg.test(str); // false
str = "15000000000\n17000000000";
let found = str.match(reg); // ['15000000000', '17000000000']
1.2、$
Match the end of the input . If the multiline mode is set to true,$ stay Before line break It can also match immediately .
let reg = /^1[3-9]\d{9}7$/gm;
let str = "25000000000";
reg.test(str); // false
str = "15000000000\n170000000007";
let found = str.match(reg); // ['170000000007']
1.3、\b
Match the boundary of a word ( Boundaries include line breaks and spaces ), This is a word before the character / There is no character position after another word .
let reg = /\bm/gm;
let str = "month\nmoom";
str.match(reg); // ['m', 'm']
reg = /th\b/gm;
str = "month\nthird";
str.match(reg); // ['th']
str = "month\nsomething";
str.match(reg); // ['th']
str = "month ufo";
str.match(reg); // ['th']
1.4、\B
Match non word boundaries .
let reg = /on\B/gm;
let str = "at noon";
str.match(reg); // null
str = "noon noon\nnoon";
str.match(reg); // null
str = "ongoing";
str.match(reg); // ['on']
2、 Other assertions
2.1、x(?=y)
Forward assertion : x By y Match when following x, Results do not include y.
let reg = /\d(?=y)/g;
let str = "1y2y3";
str.match(reg); // ['1', '2']
2.2、x(?!y)
Forward negation assertion : x Has not been y Match when following x.
let reg = /\d(?!y)/g;
let str = "1y2y3";
str.match(reg); // ['3']
2.3、(?<=y)x
Assert backward : x Follow y In the case of matching x, Results do not include y.
let reg = /(?<=y)\d/g;
let str = "y1y23";
str.match(reg); // ['1', '2']
2.4、(?<!y)x
A backward negative assertion : x Do not follow y Match when x.
let reg = /(?<!y)\d/g;
let str = "y1y23";
str.match(reg); // ['3']
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(^_^)∠※!!!

边栏推荐
- Methodology for troubleshooting problems (applicable to troubleshooting problems arising from any multi-party cooperation)
- Understanding and mastery of ffmpeg avbufferpool
- Docker installation of mysql8 and sqlyong connection error 2058 solution [jottings]
- 项目中遇到一个有趣的事情
- kaniko官方文档 - Build Images In Kubernetes
- The spiral matrix of the force buckle rotates together (you can understand it)
- Motor control Clarke( α/β) Derivation of equal amplitude transformation
- 商品服务-平台属性
- Introduction to two types of rxjs observable operators
- Unity的脚本的基础语法(2)-Unity中记录时间
猜你喜欢

资源变现小程序开通微信官方小商店教程

【精选】资源变现资讯、新闻、自媒体、博客小程序(可引流,开通流量主,带pc后台管理)

排查问题的方法论(适用于任何多方合作中产生的问题排查)

Hangzhou E-Commerce Research Institute: the official website (website) is the only form of private domain

WTM重大更新,多租户和单点登录

独立站即web3.0,国家“十四五“规划要求企业建数字化网站!

商品服务-平台属性

Wechat applet reports an error: typeerror: cannot read property 'SetData' of undefined

ABAP工具箱 V1.0(附实现思路)

Basic syntax of unity script (1) - common operations of game objects
随机推荐
How can c write an SQL parser
How to handle ZABBIX server startup failure
STM32 porting the fish component of RT thread Standard Edition
Package based on thinkphp5 -tronapi- wave field interface - source code without encryption - can be opened twice - interface document attached - detailed guidance of the author - June 30, 2022 08:45:2
发生QQ大规模盗号事件,暴露出什么网络安全问题?
Understanding and mastery of ffmpeg avbufferpool
Idea 2021.3 golang error: rning: undefined behavior version of delve is too old for go version 1.18
独立站即web3.0,国家“十四五“规划要求企业建数字化网站!
Paper interpretation (AGC) attributed graph clustering via adaptive graph revolution
MySQL implements the division of two query results
Tronapi- wavefield interface - source code without encryption - can be opened in two places - interface document attached - encapsulation based on thinkphp5 - detailed guidance of the author - 21:59:3
kaniko官方文档 - Build Images In Kubernetes
All the abnormal knowledge you want is here
排查问题的方法论(适用于任何多方合作中产生的问题排查)
力扣之螺旋矩阵,一起旋转起来(都能看懂)
golang 基础 —— 字符串 与 int 、int64 互转
顺应媒体融合趋势,中科闻歌携手美摄打造数智媒宣
JS 二维数组变一维数组的方法
Dark horse notes - common date API
Basic syntax of unity script (1) - common operations of game objects