jas999 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i'm trying to parse lines from a file that have several email addresses in them, and then print them on separate lines.

Im using the following reg ex to find the lines that have an email address.
($line =~ /[ |\t|\r|\n]*\"?([^\"]+\"?@[^ <>\t]+\.[^ <>\t][^ <>\t]+)[ | +\t|\r|\n]*/ )

This finds the lines but am having difficuly splitting the line if it has more than one email address.

Input:
$line = “TO: jas@jas1.com; 1@example.co.uk, random text jas@jas2.com ;
I'd like the output to be:
jas@jas1.com<new line> 1@example.co.uk<new line> jas@jas2.com<new line>

Could you point me in right direction?

Regards,Jas

Replies are listed 'Best First'.
Re: regular expression query
by ccn (Vicar) on Dec 27, 2008 at 21:45 UTC
    use Regexp::Common qw(Email::Address);
    use Regexp::Common qw[Email::Address]; use Email::Address; my (@found) = $line =~ /($RE{Email}{Address})/g; my (@addrs) = map $_->address, Email::Address->parse("@found"); print $_, "\n" for @addrs;