Basic knowledge of regular expressions

1 String processing function

join(): Connect the iterable object and return the result after the connection.
Insert picture description here

strip(): Remove the chars characters at both ends of the string str (\n, \t, "", usually mainly to remove spaces).
Insert picture description here

split(): Separate the string str according to the set separator, and return the separated string array.
Insert picture description here

2 regular expressions

2.1 Preliminary knowledge

On the content:
numbers\d
letters\w
other characters.
Special characters use escape characters + special characters, such as:
-space\s

Quantity control:
*: means any number, including 0
+: means at least one character
{n}: means n characters
{n, m}: means n~m characters
Example:
\d{3}: can match 3 Numbers, such as: "010"
\s: can match a space, \s+, match at least one space, such as: ""," ", etc.
\d{3, 8}: can match 3 to 8 numbers, such as: "1234567"

Question: 020-12345678
Answer: Regular expression: \d{3}-\d{3, 8}

Topic:
Use regular expressions to match mailboxes. The format of the mailbox is: only English letters, numbers, underscores, full stops, and underscores are allowed. The sample format is as follows:
[email protected]
Answer:
Insert picture description here

2.2 Advanced knowledge

Insert picture description here

2.3 re module

re module: python's regular expression module
re.match (matching pattern, string to be matched)
Insert picture description here

If the match fails, None is returned.
So, in fact, you can add a judgment, whether it is a correct match, in order to test later.
Insert picture description here

2.4 Grouping

Group, group, extract substring, and () represents the group substring to be extracted.
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_45059457/article/details/109461543