[issue44940] Hint the use of non-capturing group in re.findall() documentation

2021-08-20 Thread Rondevous


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

Initially, after going through help(re) I had associated re.findall with the 
'global' flag used in javascript regex which would return all the matches. 
Without the global flag (in javascript) only the first match is returned, like 
re.search() in python.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44940] Hint the use of non-capturing group in re.findall() documentation

2021-08-20 Thread Serhiy Storchaka


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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44940] Hint the use of non-capturing group in re.findall() documentation

2021-08-19 Thread Vedran Čačić

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 included in "a list of groups" returned.

I'm not sure how best to fix it. Maybe: Alternatively, if grouping parentheses 
are present in the pattern, return a list of groups captured by them...

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44940] Hint the use of non-capturing group in re.findall() documentation

2021-08-19 Thread Vedran Čačić

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 same thing, as far as I can see. Match is 'cool', group 1 is 
empty. Matches are not the same as groups.

--
nosy: +veky

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44940] Hint the use of non-capturing group in re.findall() documentation

2021-08-17 Thread Rondevous


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 
(?:foo) in the pattern. This was not obvious.


P.S. Making the groups non-capturing in such a pattern is not needed in 
javascript (as tested on regexr.com); could this be an issue with the | 
operator in re.findall?

--
assignee: docs@python
components: Documentation
messages: 399799
nosy: docs@python, rondevous
priority: normal
severity: normal
status: open
title: Hint the use of non-capturing group in re.findall() documentation
type: enhancement
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com