Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of regular expression examples in python

2025-04-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "regular expression instance usage in python". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Metacharacters:\ d\ w\ s\ n\ t\ b\ W\ D\ S. ^ $[] [^] () |

Metacharacters placed in the character group will appear in their original form () [cannot appear in pairs]. | |? + *-sign has a special meaning in square brackets and needs to be escaped |

Quantifier: + *? {n} {n,} {n ~ m}

Greedy matching / lazy matching:

The default is greedy matching:

Change to inert matching: quantifier?

# match as few matches as possible in the range

#? (0-1) as little as possible is 0 matches

# escape character:

# if a character with a special meaning in the rule wants it to express its original meaning, add\ before the character

# some characters with no special meaning in the rule may become characters with special meaning by adding\.

Regular expression instance

1. 2019-6-6 or 2019-06-06

^ [1-9]\ d {0Magne3}\-(1 [02] | 0? [1-9])-([12] [0-9] | [3] [01] | 0? [1-9]) $

2. Email address zh51414ferw.rewr_rewr@req.vip.cn123

@ must be preceded by content and can only be letters (uppercase and lowercase), numbers, underscore (_), minus sign (-), dot (.)

@ and the last dot (.) must have content and can only be letters (uppercase and lowercase), numbers, dots (.), minus signs (-), and the two dots cannot be next to each other.

The last dot (.) must be followed by content and the content can only be letters (case), numbers and length greater than or equal to 2 bytes, less than or equal to 6 bytes

[0-9a-zA-Z] [\ w\ -.] + @ [a-zA-Z0-9\ -] + (\ .[ a-zA-Z0-9\ -] +) *. [A-Za-z0-9] {2Power6}

3. Match the QQ number

[1-9]\ d {4pm 11}

4. Match the phone number

1 [3-9]\ d {9}

5. User password with a length of 8-10 digits: including numeric and alphanumeric underscores

[\ w] {8pm 10}

6. Matching CAPTCHA: composed of 4-digit numeric letters

[a-zA-Z0-9] {4}

[a-zA-Z\ d] {4}

7 、

From wa

Banana

Qqxing

In such a string, the wa,banana,qqxing content is matched.

>\ w + <

8. 1-2 * ((60-30 + (- 40) 5) * (9-2 "5 + 3) * (9-2" 5 + 3) * (9-2 "5 + 3) * (9-2) match the expression without other parentheses in the inner layer from the above expression

\ ([^ ()] +\) "regular expression instance usage in python" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report