The Python language is the ability to support regular expressions through the RE module.
The RE module supports:
(1) Multiple threads share the same compiled regular expression object.
(2) support named subgroups.
Common functions of the RE module
1.match () function and the use of the search () function.
Difference: The match function matches the pattern from the starting part of the string.
The search function matches the first occurrence of a given pattern in any location.
Example:
The use of the 2.group () function and the groups () function.
Difference: the group () function returns the entire matching object or returns a specific subgroup.
The groups () function returns a tuple that contains subgroups.
Example:
The use of the 3.findall () and Finditer () functions.
FindAll () Returns a list of all occurrences of a regular expression pattern in a query string that are not duplicates.
Example:
The Finditer () function is similar but more memory-efficient. The return is an iterator.
Example:
Results:
The use of the 4.sub () and SUBN () functions.
Two functions are used to implement the search substitution function.
Difference: Sub () returns only the replaced string. Instead, SUBN () returns a tuple that consists of a replacement string and a total number of replacements.
Example:
Python core programming-Regular Expression Learning notes (2)