Usando Regex en Powershell para tomar el correo electrónico
Escribí un script para capturar diferentes campos en un archivo HTML y rellenar las variables con los resultados. Estoy teniendo problemas con la expresión regular para agarrar el correo electrónico. Aquí hay un código de ejemplo:
$txt='<p class=FillText><a name="InternetMail_P3"></a>[email protected]</p>'
$re='.*?'+'([\\w-+]+(?:\\.[\\w-+]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7})'
if ($txt -match $re)
{
$email1=$matches[1]
write-host "$email1"
}
Obtuve el siguiente error:
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 <<<< $re)
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : BadOperatorArgument
¿Que me estoy perdiendo aqui? Además, ¿hay una mejor expresión regular para el correo electrónico?
Gracias por adelantado.