I wrote a script to capture various fields in an HTML file and populate the variables with the results. I have problems with regex for email capture. Here is a sample code:
$txt='<p class=FillText><a name="InternetMail_P3"></a> First.Last@company-name.com </p>' $re='.*?'+'([\\w-+]+(?:\\.[\\w-+]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7})' if ($txt -match $re) { $email1=$matches[1] write-host "$email1" }
I get the following error:
Bad argument to operator '-match': parsing ".*?([\\w-+]+(?:\\.[\\w-+]+)*@(?:[\\w-]+\\ .)+[a-zA-Z]{2,7})([\\w-+]+(?:\\.[\\w-+]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7})" - [xy] range in reverse order.. At line:7 char:16 + if ($txt -match <<<< $re) + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : BadOperatorArgument
What am I missing here? Also, is there a better regular expression for email?
Thanks in advance.
source share