REGEX extracting specific part non greedy
<p>I'm new to Python 2.7.  Using regular expressions, I'm trying to extract from a text file just the emails from input lines.  I am using the non-greedy method as the emails are repeated 2 times in the same line.  Here is my code:</p>

<pre><code>import re
f_hand = open('mail.txt')
for line in f_hand:
    line.rstrip()
    if re.findall('\S+@\S+?',line): print re.findall('\S+@\S+?',line)
</code></pre>

<p>however this is what i"m getting instead of just the email address:</p>

<pre><code>['href="mailto:secretary@abc-mediaent.com"&gt;sercetary@a']
</code></pre>

<p>What shall I use in <code>re.findall</code> to get just the email out?  </p>

<p><code>\S</code> means not a space. <code>"</code> and <code>&gt;</code> are not spaces.</p>

<p>You should use <code>mailto:([^@]+@[^"]+)</code> as the regex (quoted form: <code>'mailto:([^@]+@[^"]+)'</code>). This will put the email address in the first capture group.</p>

python regex python-2.7 non-greedy