RE module functions
Re-module functions and methods of regular expression objects
Match (pattern,string,flags=0) attempts to match a string with a pattern of regular expressions with optional tokens. If the match succeeds, the matching object is returned, and if it fails, it returns none.
Search (pattern,string,flags=0) searches for the first occurrence of a regular expression pattern in a string using an optional tag. If the match succeeds, the matching object is returned, or none if it fails
FindAll (pattern,string [, flags]) ① finds all (non-repeating) occurrences of the regular expression pattern in a string and returns a matching list
Finditer (pattern,string [, flags]) ② is the same as the FindAll () function, but returns an iterator instead of a list. For each match, the iterator returns a matching object
Split (pattern,string,max=0) ③ the Split function splits the string into a list based on the pattern delimiter of the regular expression, and then returns the list of successful matches, separating the maximum operations Max times (the default is to split all successful locations)
Re module functions and regular Expression object methods
Sub (pattern,repl,string,count=0) ③ replaces all occurrences of the pattern of the regular expression with REPL in the string, unless count is defined, otherwise the occurrence is replaced (see also SUBN () function, which returns the number of substitution operations)
Common methods of matching objects (view documents for more information)
Group (num=0) returns the entire matching object, or a specific subgroup numbered NUM
Groups (Default=none) returns a tuple containing all matched subgroups (returns an empty tuple if there is no successful match)
#-*-coding:utf-8-*-ImportRe#match ()M0 = Re.match ('AA','AA is not AA')PrintM0.group ()#Search ()M2 = Re.search ('AA','AA is not AA')PrintM2.group ()#FindAll ()M4 = Re.findall ('AA','Aa1 Aa2 Aa3')PrintM4#Sub ()M5 = Re.sub ('AA','BB','Aa1 Aa2 Aa3')PrintM5#subn ()M5 = Re.subn ('AA','BB','Aa1 Aa2 Aa3')PrintM5
[Python learning] Regular expressions