The content of this article is regular expression and the use of Python re library, now share to everyone, the need for friends can refer to the content of this article
Regular expressions and the use of the Python re library
Note: Images and related codes are sourced from MOOC
Regular expressions
Common operators for regular expressions
Regular expression Syntax instances
Regular expressions in the form of IP address strings
Use of the Python re library
The representation type of a regular expression
When the regular expression contains an escape character, use the raw string
Re Library main function function
Example
Import rematch = Re.match (R ' [1-9]\d{5} ', ' BIT 100081 ') print (Match.group (0)) # The MATCH function matches the regular expression from the beginning of a string, so the variable match should be equal to # None, so the above code will throw an exception, the correct wording is to first judge the match
Another equivalent usage of the RE library
Pat is a regular expression object compiled from a regular expression string and can directly use the functions of the 6 >re libraries above.
Match object for RE library
The properties of the match object
Greedy match and minimum match for RE Library
The RE library uses greedy matching by default, which is the output that matches the longest string