python to extract list match from email thread
<p>I m new to python. I need to retrieve the list of match </p>

<p>for Example my text is below which is an email.
I need to extract all To, From, Sent, Subject and body from a mail thread.</p>

<p>Result need to From List</p>

<p>From(1) = Crandall, Sean 
From(2) = Nettelton, Marcus  </p>

<p>To(1)= Crandall, Sean; Badeer, Robert
To(2)= Meredith, Kevin</p>

<p>Like for above Sent, subject etc</p>

<pre><code>"-----Original Message-----
From:   Crandall, Sean  
Sent:   Wednesday, May 23, 2001 2:56 PM
To: Meredith, Kevin
Subject:    RE: Spreads and Product long desc.

Kevin,

Is the SP and NP language in the spread language the same language we use when we transact SP15 or NP15 on eol?

 -----Original Message-----
From:   Meredith, Kevin  
Sent:   Wednesday, May 23, 2001 11:16 AM
To: Crandall, Sean; Badeer, Robert
Subject:    FW: Spreads and Product long desc."
</code></pre>

<p>You can use <code>re.findall()</code> for this, see: <a href="https://docs.python.org/2/library/re.html#re.findall" rel="nofollow">https://docs.python.org/2/library/re.html#re.findall</a>. E.g.</p>

<pre><code>re.findall("From:   (.*)  ", input_string);
</code></pre>

<p>would return a list of the From-names (<code>['Crandall, Sean', 'Meredith, Kevin']</code>), assuming it's always the same amount of white spaces.</p>

<p>If you want to get fancy, you could do several searches in the same expression: E.g.</p>

<pre><code>re.findall("From:   (.*)  \nSent:   (.*)", input_string);
</code></pre>

<p>would return <code>[('Crandall, Sean', 'Wednesday, May 23, 2001 2:56 PM'), ('Meredith, Kevin', 'Wednesday, May 23, 2001 11:16 AM')]</code></p>

python regex match