title: Using Regex in Powershell to grab email
body: <p>I have wrote a script to grab different fields in an HTML file and populate variables with the results. I'm having issues with the regular expression for grabbing the email. Here is some sample code:</p>
  
  <pre><code>$txt='&lt;p class=FillText&gt;&lt;a name="InternetMail_P3"&gt;&lt;/a&gt;First.Last@company-name.com&lt;/p&gt;'
  
  $re='.*?'+'([\\w-+]+(?:\\.[\\w-+]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7})'
  
  if ($txt -match $re)
  {
      $email1=$matches[1]
      write-host "$email1"
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Bad argument to operator '-match': parsing ".*?([\\w-+]+(?:\\.[\\w-+]+)*@(?:[\\w-]+\\
  .)+[a-zA-Z]{2,7})([\\w-+]+(?:\\.[\\w-+]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7})" - [x-y] range in reverse order..
  At line:7 char:16
  + if ($txt -match &lt;&lt;&lt;&lt;  $re)
      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : BadOperatorArgument
  </code></pre>
  
  <p>What am I missing here? Also, is there a better regex for email?</p>
  
  <p>Thanks in advance.</p>