当前位置:网站首页>JS regular expression system explanation (comprehensive summary)
JS regular expression system explanation (comprehensive summary)
2022-06-28 06:40:00 【Ouyang】
js Regular expression system explanation
1. Declaration and use
- Define... Through the constructor ( Generally not )
let Variable name = new RegExp(/ expression /);
- Literal direct definition ( Usually )
let Variable name = / expression /;
- Common methods ( It is generally used to detect whether the incoming string conforms to the rule and return a Boolean value )
exp.test(" String to detect ")
2. Predefined classes and escape characters
- . [^\n\r] Any character other than line feed and carriage return
- \d [0-9] Numeric character digit
- \D [^0-9] Nonnumeric character
- \w [a-zA-Z0-9_] Word characters ( All English alphanumeric and _) word
- \W [^a-zA-Z0-9_] Nonword character
- \s [\f\r\n\t\v] Invisible characters space
- \S [^\f\r\n\t\v] Visible characters
- \f Indicates page change form feed
- \t Represents a horizontal tab table
- \v Represents a vertical tab vertical table

- \r,\n,\r\n The difference between ( By the way )
In the evil old society , Typewriter line breaks (\n newline) Then it will only move down one line , You need to go back to the beginning of a line (\r return) To continue typing
The old operating system also inherited this feature of the typewriter , However, users usually return to the beginning after line breaking , Therefore, the new operating system makes it easy to Enter The meaning of the key is changed to \r\n Or directly \n The meaning of is changed to “ Move to the beginning of the next line ”. - | Represents or Or has the lowest priority Can pass () Raise priority
3. Character class
- Simple class [abc] Indicates the characters that can appear at this position
- Negative class [^abc] A character indicating that the position cannot appear
- Scope class [a-e] Indicates the range of characters that can appear at this position
- Combination class [a-xA-E0-9] Combination of range classes
4. The border , quantifiers , Brackets
- ^ Will match the starting position of the line or string
- ^ Only in [] Neicai means non On the outside, it means start
- $ Will match the end of the line or string
- ^$ together It must be this ( Exactly match )
- “*” Repeat zero or more x>=0
- “+” Repeat one or more times x>=1
- “?” Repeat zero or one time x=(0||1)
- {n} n Time x=n
- {n,} repeat n Or more times x>=n
- {n,m} The number of repetitions is more than n Duodanbi m Less n<=x<=m
- () Means a group
- [] Represents the position of a character
- {} Number of times
5. Matching commonly used in projects (CV Necessary for Engineers )
// 1. Match domestic phone number
let tel = /^0\d{2,3}-\d{7,8}$/
// 2. Match name
let name = /^[\u4e00-\u9fa5]{2,}$/
// 3. Matching Tencent QQ Number
let qq = /^[1-9]\d{4,10}$/
// 4. Match cell phone number
let phone = /^(13[0-9]|14[57]|15[0-9]|18[0-9])\d{8}$/
// 5. Match mailbox
let emai = /^\w+([+-.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
// 6. Verify Chinese
let regex = /^[\u0391-\uFFE5]+$/;
// 7. Verify ID card
let idCrad = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/;
// 8. Validation of an integer
let number = /^[-+]?\d*$/;
// 9. Verify that the date format is YYYY-MM-DD hh:mm:ss Format
let date = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
// 10. Verify that the characters entered are English letters
let en = /^[a-zA-Z]+$/
// 11. Baidu network disk link matching
// Support two link formats shared by Baidu
// Format 1 : link : https://pan.baidu.com/s/15gzY8h3SEzVCfGV1xfkJ Extraction code : vsuw Copy this content after opening baidu network disk mobile phone App, It is more convenient to operate
// Format two :http://pan.baidu.com/share/link?shareid=179436&uk=32720556 Extraction code : vsuw Copy this content after opening baidu network disk mobile phone App, It is more convenient to operate
let reg = /([http|https]*?:\/\/pan\.baidu\.com\/[(?:s\/){0,1}|(share)]*(?:[0-9a-zA-Z?=&])+)(?:.+:(?:\s)*)?([a-zA-Z]{4})?/;
// 12. Whether or not there are decimals
let objRegExp= /^\d+\.\d+$/;
// 13. Check if it's all from 8 Digit composition
let reg = /^[0-9]{8}$/
1. I hope this article can help you , If there is a mistake , Please point out
2. Originality is not easy. , Please also use your little hands to make a fortune to support a wave ( Focus on 、 Comment on 、 give the thumbs-up 、 Collection )
3. Thank you ! We will continue to offer high-quality articles in the future
4. If in doubt , You can write to me ( The home page has Q)

边栏推荐
- EasyUI reset multi condition query
- Wechat applet paging function, pull-down refresh function, direct dry goods
- 记JPA使用自定义VO接收 JPQL查询结果
- fpm工具安装
- 浮动与定位
- Mise en œuvre de l'actionneur asynchrone d'exécution à partir de zéro
- Cmake tips
- 【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
- 助力涨点 | YOLOv5结合Alpha-IoU
- JDBC learning (I) -- implementing simple CRUD operations
猜你喜欢

三极管驱动无刷电机

AutoCAD C# 多段线小锐角检测

Yygh-7-user management

借助nz-pagination中的let-total解析ng-template

搭建你jmeter+jenkins+ant

Drop down list processing in Web Automation

Freeswitch使用originate转dialplan

pytorch RNN 学习笔记

Error reporting - resolve core JS / modules / es error. cause. JS error

FPGA - 7系列 FPGA SelectIO -07- 高级逻辑资源之ISERDESE2
随机推荐
AutoCAD C polyline small acute angle detection
Rn7302 three-phase electric quantity detection (based on STM32 single chip microcomputer)
JDBC学习(一)——实现简单的CRUD操作
CAD secondary development +nettopologysuite+pgis reference multi version DLL
It will cost 700 yuan to realize this issue. Does anyone do it?
推荐10个好用到爆的Jupyter Notebook插件,让你效率飞起
Extern "C" overview
Use the SQL SELECT count distinct query statement to count the total number of unique values of a field in the database
Promotion intégrale et ordre des octets de fin de taille
FPM tool installation
Drop down list processing in Web Automation
Alibaba cloud SMS service (Complete Guide), SMS sending function implementation.
【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
Freeswitch uses Mod_ Shot module plays mp3
@RequestParam
【网络教程】IPtables官方教程--学习笔记1
Parsing ng template with let total in NZ Pagination
[staff] arpeggio mark
Is it safe to open a stock account? How to open a stock account?
Yolact++ pytoch environment