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

边栏推荐
- Hangzhou E-Commerce Research Institute: the official website (website) is the only form of private domain
- Product manager professional knowledge 50 (7) - how to establish a complete set of user growth system?
- Rk356x u-boot Institute (command section) 3.2 usage of help command
- [yitianxue awk] regular matching
- 独立站即web3.0,国家“十四五“规划要求企业建数字化网站!
- Golang Basics - string and int, Int64 inter conversion
- Package tronapi wave field interface based on thinkphp5 PHP version -- interface document attached -20220627
- Unity脚本程序的开发
- Derivation of Park transformation formula for motor control
- Js根据相同值将数组转换为二维数组
猜你喜欢

WTM major updates, multi tenancy and single sign on

Dark horse notes - common date API

Idea 2021.3 golang error: rning: undefined behavior version of delve is too old for go version 1.18

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

Goods and services - platform properties

Apache Doris Compaction优化百科全书

The independent station is Web3.0. The national "14th five year plan" requires enterprises to build digital websites!

逆向调试入门-PE中的VA与RVA换算04/07

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

Derivation of Park transformation formula for motor control
随机推荐
Today's sleep quality record 80 points
JS converts an array to a two-dimensional array based on the same value
WTM重大更新,多租户和单点登录
Rk356x u-boot Institute (command section) 3.3 env related command usage
【精选】资源变现资讯、新闻、自媒体、博客小程序(可引流,开通流量主,带pc后台管理)
golang 基础 —— 字符串 与 int 、int64 互转
力扣之螺旋矩阵,一起旋转起来(都能看懂)
Basic syntax of unity script (1) - common operations of game objects
顺应媒体融合趋势,中科闻歌携手美摄打造数智媒宣
Product manager professional knowledge 50 (7) - how to establish a complete set of user growth system?
Derivation of Park transformation formula for motor control
资源变现小程序开通微信官方小商店教程
PG Basics - logical structure management (table inheritance, partition table)
逆向调试入门-PE中的VA与RVA换算04/07
Goods and services - platform properties
The independent station is Web3.0. The national "14th five year plan" requires enterprises to build digital websites!
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
2022-06-23 sail soft part formula and SQL generation (month and quarter retrieval)
[deep anatomy of C language] storage principle of float variable in memory & comparison between pointer variable and "zero value"
【招聘(广州)】成功易(广州).Net Core中高级开发工程师