Skip to content

Commit 1e6d852

Browse files
bpo-32211: Document the existing bug in re.findall() and re.finditer(). (#4695)
1 parent f24c185 commit 1e6d852

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
@@ -719,23 +719,29 @@ form.
719719
Splitting on a pattern that could match an empty string now raises
720720
a warning. Patterns that can only match empty strings are now rejected.
721721

722+
722723
.. function:: findall(pattern, string, flags=0)
723724

724725
Return all non-overlapping matches of *pattern* in *string*, as a list of
725726
strings. The *string* is scanned left-to-right, and matches are returned in
726727
the order found. If one or more groups are present in the pattern, return a
727728
list of groups; this will be a list of tuples if the pattern has more than
728-
one group. Empty matches are included in the result unless they touch the
729-
beginning of another match.
729+
one group. Empty matches are included in the result.
730+
731+
.. note::
732+
733+
Due to the limitation of the current implementation the character
734+
following an empty match is not included in a next match, so
735+
``findall(r'^|\w+', 'two words')`` returns ``['', 'wo', 'words']``
736+
(note missed "t"). This is changed in Python 3.7.
730737

731738

732739
.. function:: finditer(pattern, string, flags=0)
733740

734741
Return an :term:`iterator` yielding :ref:`match objects <match-objects>` over
735742
all non-overlapping matches for the RE *pattern* in *string*. The *string*
736743
is scanned left-to-right, and matches are returned in the order found. Empty
737-
matches are included in the result unless they touch the beginning of another
738-
match.
744+
matches are included in the result. See also the note about :func:`findall`.
739745

740746

741747
.. function:: sub(pattern, repl, string, count=0, flags=0)

0 commit comments

Comments
 (0)