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

边栏推荐
猜你喜欢

Abaqus 2022软件安装包和安装教程

A necessary tool for testing -- postman practical tutorial

JVM FAQs

VR云展厅如何给线下实体带来活力?有哪些功能?

Buttons to achieve various effects and functions. Reading this article is enough

ABAQUS 2022最新版——完善的现实仿真解决方案

1. 爬虫之Beautifulsoup解析库&在线解析图片验证码

VR全景中特效是如何编辑的?细节功能如何展示?

企业中通过组策略管理Edge浏览器设置(IE模式、主页绑定等)

闲鱼难“翻身”
随机推荐
正则系列之字符类
哪个券商佣金的佣金最低?另外,手机开户安全么?
ABAQUS 2022最新版——完善的现实仿真解决方案
await和async
设计电商秒杀系统
How JS correctly clears all child elements under an element
当我们在看待产业互联网的时候,总是会站在消费互联网的对立面来看待它
Go语言学习教程(十三)
6-1漏洞利用-FTP漏洞利用
Wechat applets - basics takes you to understand the life cycle of applets (2)
无线充U型超声波电动牙刷方案开发
Gateway服务网关
4.3寸触控屏12路控制端口可编程网络中控支持5台中控主机相互备份
KubeVela 1.4:让应用交付更安全、上手更简单、过程更透明
IT外包驻场人员怎么定位自己的痛点?
实现各种效果和功能的按钮,读这篇文章就够了
派尔特医疗在港交所招股书二次“失效”,上市计划实质性延迟
永远不要使用Redis过期监听实现定时任务!
配置服务器环境
如何使用物联网低代码平台进行服务管理?