This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rondevous
Recipients docs@python, rondevous, serhiy.storchaka, veky
Date 2021-08-20.16:02:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1629475338.81.0.577131597297.issue44940@roundup.psfhosted.org>
In-reply-to
Content
From my understanding, "|" should match either the RegEx on the left or the RegEx on the right of the pipe
>>> help(re):
        "|"      A|B, creates an RE that will match either A or B.

With re.search(), the pattern below matches 'cool' as well as 'foo'
>>> re.search('(foo)|cool?', 'foo bar cool foobar coolbar')
<re.Match object; span=(0, 3), match='foo'>
>>> re.search('(foo)|cool?', 'cool')
<re.Match object; span=(0, 4), match='cool'>

But, the same pattern and strings won't match 'cool' if used with re.findall() or re.finditer() because of how they work when capture-groups are present in the pattern.
History
Date User Action Args
2021-08-20 16:02:18rondevoussetrecipients: + rondevous, docs@python, serhiy.storchaka, veky
2021-08-20 16:02:18rondevoussetmessageid: <1629475338.81.0.577131597297.issue44940@roundup.psfhosted.org>
2021-08-20 16:02:18rondevouslinkissue44940 messages
2021-08-20 16:02:18rondevouscreate