Rondevous <rondevu.mis...@protonmail.com> added the comment:

>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.

----------
title: Hint the use of non-capturing group in re.findall() documentation -> 
Suggest the use of non-capturing groups in re.findall() and re.finditer() docs

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44940>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to