Rondevous added the comment:
To clarify in short: the pattern I mentioned doesn't give the result I expected
in re.findall() unlike re.search()
Given pattern: (foo)?bar|cool
Maybe my approach in testing the regex first using re.search() and then using
re.findall() to return all matches
Change by Serhiy Storchaka :
--
keywords: +patch
nosy: +serhiy.storchaka
nosy_count: 3.0 -> 4.0
pull_requests: +26309
stage: -> patch review
pull_request: https://github.com/python/cpython/pull/27849
___
Python tracker
Vedran Čačić added the comment:
Ah, now I see. When some_match.group(0) is called, the whole match is returned.
So match can be considered kinda group (quasigroup?:). I see how it can be
confusing: python usually starts indexing at 0, and someone might think that a
.group(0) would be
Vedran Čačić added the comment:
It currently says:
...matches are returned in the order found. If one or more groups are present
in the pattern, return a list of groups...
I'm not quite sure how it could be clearer. Maybe "Alternatively" at the start
of the second sentence?
regexr does the
New submission from Rondevous :
Can it please be hinted in the docs of re.findall to use (?:...) for
non-capturing groups?
>>> re.findall('(foo)?bar|cool', 'cool')
['']
>>>
### I expected the result: ['cool']
After hours of frustration, I learnt that I should use a non-capturing group