In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to use regular matching expressions in the re module, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
I. the expression of the check number
1. Figures
^ [0-9]\ * $
2.n-digit number
^\ d {n} $
3. At least n-digit number
^\ d {n,} $
Number of 4.m-n bits
^\ d {mdirection n} $
5. Zero and non-zero starting numbers
^ (0 | [1-9] [0-9]\ *) $
6. A non-zero number with up to two decimal places
^ ([1-9] [0-9]\ *) + (\. [0-9] {1jue 2})? $
7. A positive or negative number with 1-2 decimal places
^ (\ -)?\ d + (\.\ d {1pr 2}) $
8. Positive, negative, and decimal
^ (\-|\ +)?\ d + (\.\ d +)? $
9. A positive real number with two decimal places
^ [0-9] + (\. [0-9] {2})? $
10. A positive real number with 1 to 3 decimal places
^ [0-9] + (\. [0-9] {1pr 3})? $
11. Non-zero positive integer
^ [1 # 9]\ d\ * $or ^ ([1 # 9] [0 # 9]\ *) {1 # 3} $or ^\ +? [1 # 9] [0 # 9]\ * $
twelve。 Non-zero negative integer
^\-[1-9] [] 0-9 "\ * $or ^-[1-9]\ d\ * $
13. Non-negative integer
^\ d $or ^ [1-9]\ d\ * | 0 $
14. Non-positive integer
^-[1-9]\ d\ * | 0$ or ^ (-\ d +) | (0 +) $
15. Non-negative floating point number
^\ d + (\.\ d +)? $or ^ [1-9]\ d\ *.\ d\ * | 0.\ d\ * [1-9]\ d\ * | 0?\ .0 + | 0 $
16. Non-positive floating point number
^ ((-\ d + (\.\ d +)?) | (0 + (\ .0 +)) $or ^ (- ([1-9]\ d\ *.\ d\ * | 0.\ d\ * [1-9]\ d\ *)) | 0?\ .0 + | 0 $
17. Positive floating point number
^ [1-9]\ d\ *.\ d\ * | 0.\ d\ * [1-9]\ d\ * $or ^ (([0-9] +. [0-9]\ * [1-9] [0-9]\ *) | ([0-9]\ * [1-9] [0-9]\. [0-9] +) | ([0-9]\ * [1-9] [0-9]\ *) $
18. Negative floating point number
^-([1-9]\ d\ *.\ d\ * | 0.\ d\ * [1-9]\ d\ *) $or ^ (0-9) +. [0-9]\ * [1-9] [0-9]\ *) | ([0-9]\ * [0-9]\. [0-9] +) | ([0-9]\ * [1-9] [0-9]\ *) $
19. Floating point number
^ (-?\ d +) (\.\ d +)? $or ^ -? ([1-9]\ d\ *.\ d\ * | 0.\ d\ * [1-9]\ d\ * | 0?\ .0 + | 0) $
Second, the expression of check characters
1. Chinese characters
^ [\ u4e00 -\ u9fa5] {0,} $
two。 English and numbers
^ [A-Za-z0-9] + $or ^ [A-Za-z0-9] {4jue 40} $
3. All characters with a length of 3-20
^. {3pm 20} $
4. A string of 26 English letters
^ [A-Za-z] + $
5. A string of 26 uppercase letters
^ [Amurz] + $
6. A string of 26 lowercase letters
^ [aMuz] + $
7. A string consisting of numbers and 26 English letters
^ [A-Za-z0-9] + $
8. A string consisting of numbers, 26 letters, or underscores
^\ w $or ^\ w {3jin20} $
9. Chinese, English, numbers including underscores
^ [\ u4E00 -\ u9FA5A-Za-z0-9 _] + $
10. Chinese, English, numbers but excluding underscores and other symbols
^ [\ u4E00 -\ u9FA5A-Za-z0-9] + $or ^ [\ u4E00 -\ u9FA5A-Za-z0-9] {2jue 20} $
11. It is forbidden to enter characters containing ~
[^ ~\ x22] +
III. Expression of special requirements
1.Email address
^\ w+ ([- +.]\ w+)\ * @\ w+ ([-.]\ w+)\ * ([-.]\ w+)\ * $
two。 domain name
[a-zA-Z0-9] [- a-zA-Z0-9] {0a-zA-Z0 62} (/. [a-zA-Z0-9] [- a-zA-Z0-9] {0girls 62}) + /.?
3.InternetURL
[a-zA-z] +: / / [^\ s]\ * or ^ http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]\*)?$
4. number
1. phone number
^ (13 [0-9] | 14 [5 | 7] | 15 [0 | 1 | 2 | 3 | 6 | 7 | 8 | 9] | 18 [0 | 1 | 2 | 3 | 5 | 6 | 7 | 9])\ d {8} $
two。 Domestic telephone number (0511-4405222, 021-87888822)
\ d {3} -\ d {8} |\ d {4} -\ d {7}
3. Regular expression of phone number (supports mobile phone number, 3-4-digit area code, 7-8-digit live broadcast number, 1-color 4-digit extension):
((\ d {11}) | ^ ((\ d {7pc8})) | (\ d {4} |\ d {3})-(\ d {3}) | (\ d {4} |\ d {3})-(\ d {4} |\ d {3} |\ d {2} |\ d {1}))-(\ d {7})-(\ d {4} |\ d {3} |\ d {2} |\ d {1}) $)
5. ID card number (15 digits, 18 digits), the last digit is the check bit, which may be a number or the character X
(^\ d {15} $) | (^\ d {18} $) | (^\ d {17} (\ d | X | x) $)
6. Account number and password
1. Whether the account number is legal (starting with letters, allowing 5-16 bytes, allowing alphanumeric underscores)
^ [a-zA-Z] [a-zA-Z0-9 _] {4pm 15} $
two。 Password (starts with a letter, is between 6 and 18 in length, and can only contain letters, numbers, and underscores)
^ [a-zA-Z]\ w {5pm 17} $
3. Strong password (must contain a combination of uppercase and lowercase letters and numbers, cannot use special characters, length between 8 and 10)
^ (? =.\ *\ d) (? =.\ * [a murz]) (? =.\ * [Amurz]) [a-zA-Z0-9] {8jue 10} $
4. Strong password (must contain a combination of uppercase and lowercase letters and numbers, can use special characters, length between 8 and 10)
^ (? =.\ *\ d) (? =.\ * [a murz]) (? =.\ * [Amurz]). {8jue 10} $
7. time
1. Date format
^\ d {4} -\ d {1pm 2} -\ d {1pm 2}
two。 12 months of the year (01-09 and 1-12)
^ (0? [1-9] | 1 [0-2]) $
3. 31 days of a month (01: 09 and 1: 31)
^ ((0? [1-9]) | (1 | 2) [0-9]) | 30 | 31) $
8.xml file
^ ([a-zA-Z] + -?) + [a-zA-Z0-9] +\. [X | X] [m | M] [l | L] $
9. Regular expressions of Chinese characters
[\ u4e00 -\ u9fa5]
10. Regular expression for blank lines
\ n\ s\ *\ r (can be used to delete blank lines)
Regular expression of 11.HTML tags
]\ * >.\ *? | (regular expression of beginning and end white space characters ^\ s\ * |\ s\ * $or (^\ s\ *) | (\ s\ * $) (which can be used to delete white space characters (including spaces, tabs, page breaks, etc.) at the beginning and end of a line, a very useful expression)
twelve。 Tencent QQ account
[1-9] [0-9] {4,} (Tencent QQ number starts from 10000)
13. China Postal Code
[1-9]\ d {5} (?!\ d) (China Postal Code is 6 digits)
14.IP address
(?: 25 [0-5] | 2 [0-4]\ d | [01]?\\ d?\\ d) {3} (?: 25 [0-5] | 2 [0-4]\ d | [01]?\ d?\\ d)
The above is how to use regular matching expressions in the re module. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.