Use of python Regular Expressions and python Regular Expressions
Python regular expressions are supported by the re module.
Three matched Functions
Match: match the regular expression only from the beginning of the string. If the match succeeds, matchobject is returned; otherwise, none is returned;
Re. match (pattern, string, flags = 0) # flags flag, used to control the matching mode of regular expressions, such as case-sensitive or multi-row matching.
Search: match all strings in the string with the regular expression. If none of the strings are matched successfully, none is returned. Otherwise, matchobject is returned. (re. search is equivalent to the default behavior in perl)
The findall method returns a list that matches the given expression;
Use
Mypatten = re. compile ("rule") # define the matching rule myresult = mypatten. match ("string") # matching result
If myresult:
Print myresult. group () # You can enter a number or name a group (? P <name> Regular Expression) # name is a valid identifier.
Same as match
Mypatten = re. compile ("rule") # define the matched rule myresult = mypatten. findall ("string") # returns a list. If a group exists, a two-dimensional list is returned.
If myresult:
Print myresult. group ()
The above section describes the use of python regular expressions. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!