@@ -824,10 +824,20 @@ form.
824
824
.. function :: findall(pattern, string, flags=0)
825
825
826
826
Return all non-overlapping matches of *pattern * in *string *, as a list of
827
- strings. The *string * is scanned left-to-right, and matches are returned in
828
- the order found. If one or more groups are present in the pattern, return a
829
- list of groups; this will be a list of tuples if the pattern has more than
830
- one group. Empty matches are included in the result.
827
+ strings or tuples. The *string * is scanned left-to-right, and matches
828
+ are returned in the order found. Empty matches are included in the result.
829
+
830
+ The result depends on the number of capturing groups in the pattern.
831
+ If there are no groups, return a list of strings matching the whole
832
+ pattern. If there is exactly one group, return a list of strings
833
+ matching that group. If multiple groups are present, return a list
834
+ of tuples of strings matching the groups. Non-capturing groups do not
835
+ affect the form of the result.
836
+
837
+ >>> re.findall(r ' \b f[a-z ]* ' , ' which foot or hand fell fastest' )
838
+ ['foot', 'fell', 'fastest']
839
+ >>> re.findall(r ' ( \w + ) =( \d + ) ' , ' set width=20 and height=10' )
840
+ [('width', '20'), ('height', '10')]
831
841
832
842
.. versionchanged :: 3.7
833
843
Non-empty matches can now start just after a previous empty match.
0 commit comments