当前位置:网站首页>Character class of regular series
Character class of regular series
2022-06-30 19:45:00 【Old__ L】
Catalog
Character classes can distinguish between various characters , For example, distinguish between letters and numbers .
1、.
Has one of the following meanings :
- Matches any single character except the line terminator :
\n( A newline ),\r( A carriage return ),\u2028( Line separator )perhaps\u2029( Paragraph separator ).
let reg = /.y/g;
let str = "yes make my day";
str.match(reg); // ['my', 'ay']
- In the character set , Point loses its special significance , And match with the text points .
let reg = /\./g;
let str = ".u";
str.match(reg); // ['.']
Be careful ,m Multiline flags do not change the behavior of points . therefore , To match multiline patterns , You can use character classes [^], It will match any character including the newline character .
let reg = /[^]/g;
let str = ".u\n\r\u2028\u2029";
str.match(reg); // ['.', 'u', '\n', '\r', '
', '
']
ES2018 Added s“dotAll” sign , It allows the dot to also match the line terminator .
let reg = /./g;
let str = "yes make my day\n";
str.match(reg); // ['y', 'e', 's', ' ', 'm', 'a', 'k', 'e', ' ', 'm', 'y', ' ', 'd', 'a', 'y']
reg = /./gs;
str.match(reg); // ['y', 'e', 's', ' ', 'm', 'a', 'k', 'e', ' ', 'm', 'y', ' ', 'd', 'a', 'y', '\n']
2、\d
Match any number ( Arabic numerals ). amount to [0-9].
let reg = /\d/g;
let str = "B2is the suite number";
str.match(reg); // ['2']
3、\D
Match any non number ( Arabic numerals ) The characters of . amount to [^0-9].
let reg = /\D/g;
let str = "B2is the suite number";
str.match(reg); // ['B', 'i', 's', ' ', 't', 'h', 'e', ' ', 's', 'u', 'i', 't', 'e', ' ', 'n', 'u', 'm', 'b', 'e', 'r']
4、\w
Matches any alphanumeric character in the Basic Latin alphabet , Include underline . amount to [A-Za-z0-9_].
let reg = /\w/g;
let str = "B2is_the-suite number";
str.match(reg); // ['B', '2', 'i', 's', '_', 't', 'h', 'e', 's', 'u', 'i', 't', 'e', 'n', 'u', 'm', 'b', 'e', 'r']
5、\W
Match any word character that is not from the Basic Latin alphabet . amount to [^A-Za-z0-9_].
let reg = /\W/g;
let str = "B2is_the-suite number";
str.match(reg); // ['-', ' ']
6、\s
Match a single white space character , Including Spaces 、 tabs 、 Page identifier 、 Line breaks and other Unicode Space . amount to [ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff].
let reg = /\s/g;
let str = "B2is_the-suite number\f\n\r\t\v\u00a0\u1680\u2000\u200a\u2028\u2029\u202f\u205f\u3000\ufeff";
str.match(reg);// [' ', '\f', '\n', '\r', '\t', '\v', ' ', ' ', ' ', ' ', '
', '
', ' ', ' ', ' ', '']
7、\S
Match single characters other than spaces . amount to [^ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff].
reg = /\S/g;
str.match(reg); // ['B', '2', 'i', 's', '_', 't', 'h', 'e', '-', 's', 'u', 'i', 't', 'e', 'n', 'u', 'm', 'b', 'e', 'r']
8、\t
Match horizontal tabs .
let reg = /\t/g;
let str = "B2is_the-suite number\f\n\r\t\v\u00a0\u1680\u2000\u200a\u2028\u2029\u202f\u205f\u3000\ufeff";
str.match(reg); // ['\t']
9、\r
Match carriage return .
let reg = /\r/g;
let str = "B2is_the-suite number\f\n\r\t\v\u00a0\u1680\u2000\u200a\u2028\u2029\u202f\u205f\u3000\ufeff";
str.match(reg); // ['\r']
10、\n
Match newline .
let reg = /\n/g;
let str = "B2is_the-suite number\f\n\r\t\v\u00a0\u1680\u2000\u200a\u2028\u2029\u202f\u205f\u3000\ufeff";
str.match(reg); // ['\n']
11、\v
Match vertical tabs .
let reg = /\v/g;
let str = "B2is_the-suite number\f\n\r\t\v\u00a0\u1680\u2000\u200a\u2028\u2029\u202f\u205f\u3000\ufeff";
str.match(reg); // ['\v']
12、\f
Match page breaks .
let reg = /\f/g;
let str = "B2is_the-suite number\f\n\r\t\v\u00a0\u1680\u2000\u200a\u2028\u2029\u202f\u205f\u3000\ufeff";
str.match(reg); // ['\f']
13、[\b]
Match backspace key .
14、\0
Match one NUL character . Don't add another number after this .
15、\cX
Use caret to match control characters , among “X” yes A–Z One of the letters in ( Corresponding to code point U+0001–U+001F).
let reg = /\cM/g;
let str = "\r\t";
str.match(reg); // ['\r']
16、\xhh
Match with code hh( Two hexadecimal numbers ) Corresponding characters .
17、\uhhhh
Match with value hhhh( Four hexadecimal numbers ) Corresponding UTF-16 Code unit .
18、\u{hhhh} or \u{hhhhh}
( Only if u When marking .) Match with Unicode value U+hhhh or U+hhhhh( Hexadecimal number ) Corresponding characters .
19、\p{UnicodeProperty},\P{UnicodeProperty}
According to the character Unicode Character attributes match characters ( for example , Only match emoticon characters 、 Japanese katakana characters 、 Chinese kanji characters or Japanese Kanji characters, etc ).
20、\
Indicates that special treatment or “ escape ” Following character . It appears in one of two ways .
- For characters that are usually treated literally , Indicates that the next character is special , It cannot be explained literally . for example ,
/b/Matching character“b”. By means of“b”Put a backslash in front , That is to use/\b/, Characters become special to represent matching word boundaries . - Usually treated as special characters , Indicates that the next character is not special , It should be interpreted literally . for example ,
“*”It's a special character , Indicates that it should match the previous characters0Times or times ; for example ,/a*/Show matching0One or more“a”. To match literally*It needs to be preceded by a backslash ; for example ,/a\*/matching“a*”.
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(^_^)∠※!!!

边栏推荐
- VR云展厅如何给线下实体带来活力?有哪些功能?
- Code shoe set - mt3435 · assignment - bipartite graph problem - Graphic explanation
- Lombok
- 6-1漏洞利用-FTP漏洞利用
- 码蹄集 - MT3435 · 赋值 - 二分图问题 - 图文讲解
- sql是否走索引
- [JetsonNano] [教程] [入门系列] [一] 如何开启VNC共享
- 请指教在线开户是什么意思?究竟网上开户是否安全么?
- Why do more and more people choose cloud rendering?
- ArcGIS no plug-in load (no offset) day map
猜你喜欢
![[solved] how does Tiktok cancel paying attention to the cancelled account](/img/1f/7b0bd2c0f69f7f3d1c25c426cc5771.png)
[solved] how does Tiktok cancel paying attention to the cancelled account

【LeetCode】【SQL】刷题笔记

测试人进阶技能:单元测试报告应用指南

为什么越来越多的人选择云渲染?

How to use the low code platform of the Internet of things for service management?

更智能!AIRIOT加速煤炭行业节能减排升级

盘点华为云GaussDB(for Redis)六大秒级能力

ArcGIS no plug-in load (no offset) day map

测试必备工具 —— Postman实战教程

Advanced skills of testers: a guide to the application of unit test reports
随机推荐
mysql中union和union all的区别
Whether the SQL is indexed
今早,投资人开始集体出差
【NLP】【TextCNN】 文本分类
[multithreading] use the thread pool to implement a simple thread pool
Abaqus 2022软件安装包和安装教程
JVM常见问题
ArcGIS no plug-in load (no offset) day map
[solved] how does Tiktok cancel paying attention to the cancelled account
matlab Delaunay 三角剖分内的查询点
VR云展厅如何给线下实体带来活力?有哪些功能?
码蹄集 - MT3435 · 赋值 - 二分图问题 - 图文讲解
What securities dealers recommend? In addition, is it safe to open a mobile account?
实现各种效果和功能的按钮,读这篇文章就够了
软件工程最佳实践——项目需求分析
英语没学好到底能不能做coder,别再纠结了先学起来
VR全景拍摄为什么要加盟?巧借资源实现共赢
Which brokerage has the lowest commission? In addition, is it safe to open a mobile account?
闲鱼难“翻身”
MySQL数据库查询优化