Tag: Relative import contains margin Imp expression regular expression string Tran
Python re module findall function usage Brief
code Example:
1>>>Import re2>>> s ="adfad asdfasdf asdfas asdfawef ASD Adsfas" 3 4>>> reObj1 = Re.compile ('((\w+) \s+\w+)') 5>>>Reobj1.findall (s)6[('Adfad asdfasdf','Adfad'), ('Asdfas asdfawef','Asdfas'), ('ASD Adsfas','ASD')] 7 8>>> reObj2 = Re.compile ('(\w+) \s+\w+') 9>>>Reobj2.findall (s)Ten['Adfad','Asdfas','ASD'] One A>>> reObj3 = Re.compile ('\w+\s+\w+') ->>>Reobj3.findall (s) -['Adfad asdfasdf','Asdfas asdfawef','ASD Adsfas']
View CodeDetailed:
The FindAll function returns a list of all occurrences of a regular expression in a string, where the "results" in the list are presented, that is, the information contained in the list is returned in FindAll.
@1. When there are multiple parentheses in the given regular expression, the element of the list is the same as the number of strings in the Tuple,tuple, and the string content corresponds to the regular expression in parentheses, and the emission order is in parentheses.
@2. When a given regular expression has a parenthesis, the element of the list is a string, and the contents of the string correspond to the regular expression in parentheses (not the match for the entire regular expression).
@3. When there are no parentheses in the given regular expression, the element of the list is a string that matches the entire regular expression.
original link
Python re module findall function usage Brief