<div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Message: 6<br>
Date: Sun, 15 Apr 2012 08:48:10 +0100<br>
From: Alan Gauld &lt;<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>&gt;<br>
To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>
Subject: Re: [Tutor] re.search() help<br>
Message-ID: &lt;jmdufr$478$<a href="mailto:1@dough.gmane.org">1@dough.gmane.org</a>&gt;<br>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br>
<br>
On 15/04/12 08:10, Michael Lewis wrote:<br>
&gt; Hi everyone,<br>
&gt;<br>
&gt; I am a bit confused on how one would ever use re.search(). It<br>
&gt; essentially tells me the location on (RAM?) if the pattern matches?<br>
<br>
No it returns a MatchObject instance.<br>
You can then perform various operations on the<br>
MatchObject to, for example find the substring<br>
which actually matched.<br>
<br>
 &gt; What is the purpose of this?<br>
<br>
So that you can find the section of a long string that<br>
first matches your regex.<br></blockquote><div><br></div><div>Why not use re.findall() for that? It seems like re.findall() can fill this need and I wouldn&#39;t need to use re.search()? Can you compare an example circumstance where one would be better suited than the other?</div>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<br>
--<br>
Alan G<br>
Author of the Learn to Program web site<br>
<a href="http://www.alan-g.me.uk/" target="_blank">http://www.alan-g.me.uk/</a><br></blockquote></div><div><br></div>-- <br><div dir="ltr"><div>Michael J. Lewis</div>
<div><a href="mailto:mjolewis@gmail.com" target="_blank">mjolewis@gmail.com</a></div></div><br>
</div>