Python combat: common regular expressions Summary
- First, check the mailbox
- Second, multi-mailbox check
- Third, check the URL
- Fourth, check the phone number
- Five, IP address check
- Sixth, check the file path and extension
- Seven user password verification
- Eight, Html color values check
- Nine, calibration date
- Ten, extracted page image tag
- XI, ID check
- Twelve, the amount of the check
- XIII, the amount converted thousands separator character
- Fourth, matching license plate number
- Five, matching train trips
First, check the mailbox
Login E-mail rules are as follows: domain login name @ hostname
^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
Second, multi-mailbox check
Connecting a plurality of mailboxes, divided by semicolons
^((([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6}\;))*(([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})))$
Third, check the URL
Http format has been an example:
^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$
Fourth, check the phone number
13, 15 at the beginning of the domestic mobile phone number regular expression
^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$
Five, IP address check
IP-v4 address check
\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
IP-v6 address check
(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))
Sixth, check the file path and extension
To txt file extension, for example
^([a-zA-Z]\\:|\\\\)\\\\([^\\]+\\)*[^\\/:*?"<>|]+\\.txt(l)?$
Seven user password verification
Strength of the password must contain a combination of uppercase and lowercase letters and numbers, special characters can not be used, a length of between 8-10.
^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
Eight, Html color values check
- Hexadecimal color values are represented by the red, green, blue (RGB).
- Minimum value is 0 for each color (hex 00), the highest value of 255 (hex FF).
- Hexadecimal values are written as three numbers followed by # or six hexadecimal characters.
- Three-digit notation: #RGB, converted to a 6-digit number as: #RRGGBB.
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
Nine, calibration date
Matching 12-hour clock time format
^(?:1[0-2]|0?[1-9]):[0-5]\d:[0-5]\d$
Matching 24-hour clock time format
^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$
Ten, extracted page image tag
\\< *[img][^\\>]*[src] *= *[\\"\']{0,1}([^\\"\'\ >]*)
XI, ID check
15 ID check
^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$
18 for the ID check
^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$
Twelve, the amount of the check
The amount of decimals, accurate to two decimal places
/^[0-9]+(.[0-9]{2})?$/
XIII, the amount converted thousands separator character
return total.toString().replace(/\B(?=(\d{3})+$)/g, ',');
Fourth, matching license plate number
Matching ordinary vehicles
^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$
Match the amount of new energy vehicles
^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}(([0-9]{5}[DF])|([DF][A-HJ-NP-Z0-9][0-9]{4}))$
Five, matching train trips
[GCDZTSPKXLY1-9]\d{1,4}$