E-mail-Address-Extractor via RegEx

by Jun 23, 2010

Regular expressions are extremely powerful – and complex. Fortunately, there are plenty of sources for good regular expressions that describe all kinds of patterns. This is how you turn a RegEx pattern into a regular expression engine:

$regex = [RegEx]'(?i)s[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}s'

$regex now is a highly specialized filter for extracting e-mail addresses from text. Use this to list all emails in $text:

$regex.Matches($text) | Select-Object -ExpandProperty Value