Python regex for email addresses, need to weed out dot dash
<p>I have created this regular expression to weed out obviously wrong email addresses. For my large data set it works for 98% of cases. </p>

<pre><code>pattern = re.compile('^([a-zA-Z0-9._-]+)([a-zA-Z0-9]@[a-zA-Z0-9])([a-zA-Z0-9.-]+)([a-zA-Z0-9]\.[a-zA-Z]{2,3})$')
</code></pre>

<p>The part where the problem is is here:</p>

<pre><code>([a-zA-Z0-9.-]+)
</code></pre>

<p>It is okay if an email address has a dash in the domain, or a period, but I don't want these two symbols to be allowed consecutively such as <code>.- or -.</code></p>

<p>For example, these are okay (and should match the regex):</p>

<pre><code>chris@data.services.com
chris@data-services.com
</code></pre>

<p>But this is not (and should not yield a match):</p>

<pre><code>chris@data.-services.com
</code></pre>

<p>I have read extensively and tried all kinds of options around creating another group in the regex like <code>([\.]|[\-])?</code> to no avail. Can someone help?</p>