[Tutor] re.search() help

Alan Gauld alan.gauld at btinternet.com
Mon Apr 16 01:28:59 CEST 2012


On 16/04/12 00:20, Michael Lewis wrote:

>      > What is the purpose of this?
>
>     So that you can find the section of a long string that
>     first matches your regex.
>
>
> Why not use re.findall() for that? It seems like re.findall() can fill
> this need and I wouldn't need to use re.search()? Can you compare an
> example circumstance where one would be better suited than the other?

Performance.
It's faster to find just the first occurrence.
Especially if the string is long - say several million characters.

If you only need the first one why search for all the rest?


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list