Rondevous added the comment:
I was frustrated for hours when I couldn't figure out why this won't match:
>>> re.findall(r'(foo)?bar|cool', 'cool')
Now I know, I have to make this change: (?:foo)
But this isn't obvious.
Should it be mentioned in
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 fru
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 ma
Rondevous 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 b
Rondevous added the comment:
Maybe the functionality of re.findall and re.finditer is limited because, e.g.
I can't do something like this:
https://stackoverflow.com/questions/3512471/what-is-a-non-capturing-group-in-regular-expressions#3513858
The workaround for doing that might need
Rondevous added the comment:
To produce the same results that you'd get by using the global flag in
javascript regex, and make re.findall to not capture the groups exclusively,
all the groups in the pattern need to be of the non-capturing (?:) type.
If the distinction about capturin
Rondevous added the comment:
Oops, I was wrong about re.finditer :D
Sorry, I think didn't check that properly.
Just saw the changes. The patch looks good :)
Thanks a lot!
--
title: Suggest the use of non-capturing groups in re.findall() and
re.finditer() docs -> Cla