> Hold on, what is finditer().group(1) supposed to mean here? You’d need
next(finditer()).group(1) or next(m.group(1) for m in finditer()) or
something.

That was a mistake, I intended to write re.search().group(1), not
re.finditer().group(1). I clarified this in another reply to the thread
about an hour ago. Sorry for the confusion, I wrote the reply after being
up for a while and got re.findter() and re.search() mixed up in my head.
You're correct.

On Sat, Dec 7, 2019 at 7:57 PM Andrew Barnert <abarn...@yahoo.com> wrote:

> On Dec 7, 2019, at 04:51, Kyle Stanley <aeros...@gmail.com> wrote:
>
>
> Alternatively: creating a new section under
> https://docs.python.org/3.8/library/re.html#regular-expression-examples,
> titled "Finding the first match", where it briefly explains the difference
> in behavior between using re.findall()[0] and re.finditer().group(1) (or
> re.finditer.group() when there's not a subgroup).
>
>
> Hold on, what is finditer().group(1) supposed to mean here? You’d need
> next(finditer()).group(1) or next(m.group(1) for m in finditer()) or
> something. But if you just want the first match, why are you using either
> findall or finditer instead of just search? Isn’t that exactly the
> confusion this thread was hoping to resolve, rather than forcing even more
> novices to deal with it by pushing them into it in a section named “Finding
> the first match”?
>
> Also (when there are subgroups), surely the relevant difference is either
> between findall()[0][0] and next(finditer()).group(1), which both return
> the first group of the first match, or between findall()[0] and
> next(finditer()).groups(), which both return a tuple of groups of the first
> match, not between findall()[0] and next(finditer()).group(1), which return
> a tuple vs. just the first one?
>
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/O4AUPOBOJJPPUMBPXJ2PRZPFY33CTJ6J/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to