[Tutor] re.search() help

Michael Lewis mjolewis at gmail.com
Mon Apr 16 01:20:49 CEST 2012


>
> Message: 6
> Date: Sun, 15 Apr 2012 08:48:10 +0100
> From: Alan Gauld <alan.gauld at btinternet.com>
> To: tutor at python.org
> Subject: Re: [Tutor] re.search() help
> Message-ID: <jmdufr$478$1 at dough.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 15/04/12 08:10, Michael Lewis wrote:
> > Hi everyone,
> >
> > I am a bit confused on how one would ever use re.search(). It
> > essentially tells me the location on (RAM?) if the pattern matches?
>
> No it returns a MatchObject instance.
> You can then perform various operations on the
> MatchObject to, for example find the substring
> which actually matched.
>
>  > 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?

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

-- 
Michael J. Lewis
mjolewis at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120415/b42f2168/attachment.html>


More information about the Tutor mailing list