Regular describes a string matching pattern, but for many people writing regular is "Landry's torture". If you don't need to use it frequently, you won't even think about learning it. This article will sort out and share with you some commonly used regular expressions. Do you want to use regular expressions for free? Come and collect it!
You want to have sex for free, right? This article will give you enough at one time! Rush 99 first! (If you still think it’s not enough, just leave a comment and add more. This article will continue to be updated and added!!)
Another little tip, students who have difficulty reading can use this websitejex.im/ regulex/, visualize regular rules and fall in love with reading regular rules!
For example: regular rules for verifying email addresses: ^\w ([- .]\w )*@\w ([-.]\w )*\.\w ([-.] \w )*$
After visualization, just look at the pictures and talk, novices can do it, it’s really tql! !
Okay, let’s rush!
Mobile phone number (starting with 1): /^(?:(?:\ |00)86 )?1\d{10}$/
Mobile phone number (starting with 13 to 19): /^(?:(?:\ |00) 86)?1[3-9]\d{9}$/
Mobile phone number (starting with the mobile phone number range announced by the Ministry of Industry and Information Technology): /^( ?:(?:\ |00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])| (?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/
Domestic landline number: /\d{3}-\d{8}|\d{4}-\d{7}/
Email number: /^\w ([- .]\w )*@\w ([-.]\w )*\.\w ([-. ]\w )*$/
Postal code: /[1-9]\d{5}(?!\d)/
ID number: /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1 -9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/
Bank card number (public and private account): /^[1-9]\d{9,29}$/
License number: /^[Beijing, Tianjin, Shanghai, Chongqing, Hebei, Yunnan, Liaoning, Hunan, Anhui, Shandong, New Jiangsu, Zhejiang, Jiangxi, Hubei, Guangxi, Gansu, Shanxi, Mongolia, Shaanxi, Jilin, Fujian, Guangdong, Qinghai, Tibet, Sichuan, Ningqiong, Ambassador][A-HJ-NP-Z][A -HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9 HONG KONG and MACAO]$/
/^[1-9][0-9]{4,10}$/
/^[a-zA-Z ][-_a-zA-Z0-9]{5,19}$/
/^\d (?:\ .\d ){2}$/
* ):
/^\d{1,}$/
##Non-positive integers:
Negative integers:
##Non-negative integer:
/^\d $/
Floating point number:
/^(-?\d )(\.\d )?$/
##Positive floating point number: /^[ 1-9]\d*\.\d*|0\.\d*[1-9]\d*$/
Negative floating point number: /^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)/
Decimal: /^-?\d \.\d $/
Positive/Negative/Decimal: /^(\-|\ ) ?\d (\.\d )?$/
Positive real numbers retain 2 decimal places: /^[0-9] (.[0- 9]{2})?$/
Positive real numbers retain 1 to 3 digits after the decimal point: /^[0-9] (.[0-9]{1,3})?$/
n digits: /^\d{n}$/
At least n digits: / ^\d{n,}$/
Numbers from m to n digits: /^\d{m,n}$/
Contains at least one of the numbers and letters: /^[A-Za-z0-9] $/
Must Contains numbers and letters: /^(?=.*[a-zA-Z])(?=.*\d). $/
/^([a-f\d]{32}|[A-F\d]{32})$/
##Half-width symbols:
Chinese characters , at least one of English, numbers, and underscores:
does not contain the character "~ ”:
Characters are repeated continuously:
12 hour time (hh :mm:ss):
24-hour time (HHmmss):
Date 1 (yyyy-MM-dd, such as 2222-01-01 , the year must be 4 digits):
Date 2 (such as 333-01-01, the year can be less than 4 digits):
Date 3 (yyyyMMdd, such as 20220202):
Date time 1 (YYYYMMDD HH:mm:ss):
Date Time 2:
12 months a year ((01~09 or 1~12)) :
31 days in a month (01~09 or 1~ 31):
A month with 31 days:
##A month with 30 days:
/(0[469]|11)-(0[1-9]|[12][0-9]|30)/
2 months 28 days ("02-28"):
/^02-(0[1-9]|[1][0-9]|2[0-8])$/
Leap year:
/^(((19|20)([13579][26]|[2468][048]|0[48]))|(2000))$/
February in a leap year (such as 2008-02-01):
/^(((19|20)([13579][26]|[2468] [048]|0[48]))|(2000))-0?2-(0?[1-9]|[12]\d)$/
Date (including leap year, big and small month judgment):
/((((19|20)\d{2})-(0?(1|[3-9])|1[012]) -(0?[1-9]|[12]\d|30))|(((19|20)\d{2})-(0?[13578]|1[02])-31)| (((19|20)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|((((19|20)([ 13579][26]|[2468][048]|0[48]))|(2000))-0?2-29))$/
Year Interval-year (such as 19 to 20 years):
/^((19|20)\d{2})$/
##Year interval-year Month (such as 1999-01): /^((((19|20)\d{2})-(0?[13-9]|1[012]))|(((19|20 )\d{2})-(0?[13578]|1[02]))|(((19|20)\d{2})-0?2)|((((19|20)( [13579][26]|[2468][048]|0[48]))|(2000))-0?2))$/
Year range -Year, month and day (such as 1999-01-01): /^((((19|20)\d{2})-(0?[13-9]|1[012])-(0 ?[1-9]|[12]\d|30))|(((19|20)\d{2})-(0?[13578]|1[02])-31)|((( 19|20)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((19|20)([13579][ 26]|[2468][048]|0[48]))|(2000))-0?2-29))$/.test('2021-02-21')$/
Year interval - year, month and day (the interval symbol can be - / or empty): /^(?:(?:1[6-9]|[2-9][ 0-9])[0-9]{2}([-/.]?)(?:(?:0?[1-9]|1[0-2])\1(?:0?[ 1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(? :0?[13578]|1[02])\1(?:31))|(?:(?:1[6-9]|[2-9][0-9])(?:0[ 48]|[2468][048]|[13579][26])|(?:16|[2468][048]|[3579][26])00)([-/.]?)0?2 \2(?:29))$/
Programming related
Extract web page color code: /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
Video link address: /^https?:\/\/(. \/) . (\.(swf|avi|flv|mpg|rm|mov|wav|asf |3gp|mkv|rmvb|mp4))$/i
Picture link address:/^https?:\/\/(. \/) . (\.(gif|png|jpg|jpeg|webp|svg|psd|bmp|tif))$/i
/^( (([a-f0-9]{2}:){5})|(([a-f0-9]{2}-){5}))[a-f0-9]{2}$/ i
/^((?:(?:25[0-5]|2[0-4]\\d| [01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d ))$/
/^([a-zA-Z]\\:|\\\\)\\\\ ([^\\\\] \\\\)*[^\\/:*?"|] \\.txt(l)?$/
/^([a-zA-Z_]\w*) ([.][a-zA-Z_]\w*) $/
/^([a-zA-Z] -?) [a-zA-Z0-9] \\.[x|X][m|M ][l|L]$/
//g
/]*>(.*?)?/
/]*>.*?\1>|/
This article briefly organizes a wave of regular rules, many of which are also learned while reading, with the help of jex .im/regulex/, awesome!
If you have anything to add, please leave a comment, or if you find any errors, please point them out and they will be corrected immediately. I hope it can be helpful to your regular learning and use~
Original address: https://juejin.cn/post/7119242343798013959More programming related For knowledge, please visit:programming teaching
! !