On Wed, Dec 4, 2019 at 8:54 AM Random832 <random...@fastmail.com> wrote:
> On Wed, Dec 4, 2019, at 11:05, Guido van Rossum wrote: > > Not so fast. re.search() returns a Match object, while re.finditer() > > and re.findall() return strings. For people who are just interested in > > strings, the Match object is just a distraction. I think I am +1 on > > adding re.findfirst() as proposed by the OP. > > Er, findall returns strings, but finditer returns match objects. Sorry, my bad. Strike finditer() then, the point about findall() being different stands. > And as a side note, PEP 505 would allow the case of wanting the string or > None to be written as re.search(...)?.group(0). > Still not a particularly discoverable solution. (Given that regular expressions are often used by less sophisticated users.) > (Since findall returns a list, it can be written as ....findall(...)[0], > which is much better than next(iter(....findall(...))).) > Sure, but because both of these fail if there are no matches, we can't use them in general, and findfirst() is meant to address that by having a default rather than failing in that case. -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________ 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/BWKJJFUSV6J33BPF2SYWJHQW2BHIG36M/ Code of Conduct: http://python.org/psf/codeofconduct/