Skip to content

Commit ca54740

Browse files
[2.7] bpo-32211: Document the existing bug in re.findall() and re.finditer(). (GH-4695). (#5096)
(cherry picked from commit 1e6d852)
1 parent 0bcba37 commit ca54740

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Doc/library/re.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,21 @@ form.
611611
Added the optional flags argument.
612612

613613

614+
614615
.. function:: findall(pattern, string, flags=0)
615616

616617
Return all non-overlapping matches of *pattern* in *string*, as a list of
617618
strings. The *string* is scanned left-to-right, and matches are returned in
618619
the order found. If one or more groups are present in the pattern, return a
619620
list of groups; this will be a list of tuples if the pattern has more than
620-
one group. Empty matches are included in the result unless they touch the
621-
beginning of another match.
621+
one group. Empty matches are included in the result.
622+
623+
.. note::
624+
625+
Due to the limitation of the current implementation the character
626+
following an empty match is not included in a next match, so
627+
``findall(r'^|\w+', 'two words')`` returns ``['', 'wo', 'words']``
628+
(note missed "t"). This is changed in Python 3.7.
622629

623630
.. versionadded:: 1.5.2
624631

@@ -631,8 +638,7 @@ form.
631638
Return an :term:`iterator` yielding :class:`MatchObject` instances over all
632639
non-overlapping matches for the RE *pattern* in *string*. The *string* is
633640
scanned left-to-right, and matches are returned in the order found. Empty
634-
matches are included in the result unless they touch the beginning of another
635-
match.
641+
matches are included in the result. See also the note about :func:`findall`.
636642

637643
.. versionadded:: 2.2
638644

0 commit comments

Comments
 (0)