当前位置:网站首页>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)

边栏推荐
- CRC32概述以及实现和使用
- Differences between basic types and packaging classes
- 创建格式化时间,格式化时区的gson对象。json解析时间格式化 ZonedDateTime
- What if the applet page is set to 100% height or left blank?
- Error reporting - resolve core JS / modules / es error. cause. JS error
- API learning of OpenGL (2006) glclientactivetexture
- Install redis on windows and permanently change the password, and integrate redis with the SSM framework
- 普歌 -- getOrDefault()方法理解
- Wechat applet paging function, pull-down refresh function, direct dry goods
- ROS rviz_ Satellite function package visualizes GNSS track and uses satellite map
猜你喜欢

Freeswitch sets the maximum call duration

Exception handling (I) -- null pointer and array index out of bounds

Some habits of it veterans in the workplace

AutoCAD C# 多段線小銳角檢測

推荐几款0代码、免费、现学现用的可视化工具

Parsing ng template with let total in NZ Pagination

RN7302三相电量检测(基于STM32单片机)

CAD二次开发+NetTopologySuite+PGIS 引用多版本DLL问题

The custom cube UI pop-up dialog supports multiple and multiple types of input boxes

报错--解决core-js/modules/es.error.cause.js报错
随机推荐
JDBC学习(一)——实现简单的CRUD操作
Interpretation of Blog
Deleting MySQL under Linux
Causes of wechat applet compilation page blank bug
Freeswitch uses Mod_ Shot module plays mp3
What if the applet page is set to 100% height or left blank?
Introduction to Qualcomm platform WiFi -- Wi Fi display software
@RequestParam
AttributeError: 'callable_iterator' object has no attribute 'next'
Puge -- understanding of getordefault() method
Last 29 days
图片按日期批量导入WPS表格
最后的二十九天
普歌 -- 单例模式
【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
FPGA - 7 Series FPGA selectio -09- io of advanced logic resources_ FIFO
FPGA - 7系列 FPGA SelectIO -07- 高级逻辑资源之ISERDESE2
API learning of OpenGL (2007) gltexcoordpointer
【Rust日报】2020-05-24 Rash, Rocket, Mun, Casbin
Note that JPA uses a custom VO to receive jpql query results