1 String processing function
join(): Connect the iterable object and return the result after the connection.
strip(): Remove the chars characters at both ends of the string str (\n, \t, "", usually mainly to remove spaces).
split(): Separate the string str according to the set separator, and return the separated string array.
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:
2.2 Advanced knowledge
2.3 re module
re module: python's regular expression module
re.match (matching pattern, string to be matched)
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.
2.4 Grouping
Group, group, extract substring, and () represents the group substring to be extracted.