in reply to Re: pattern match e-mail addresses
in thread pattern match e-mail addresses

There is a CPAN module that will match email addresses inside a string; Email::Find. Here's an example using this module:

#!/usr/bin/perl -w use strict; use Email::Find qw(find_emails); use vars qw(@MATCHES); my $text = 'user@somewhere.com not an email address me@home.com'; find_emails($text, \&callback); print join "\n", @MATCHES; sub callback { my $email = shift; my $original = shift; push @MATCHES, $email->format; return $original; }

Warning: the find_emails() routine will modify the original text. Make sure that you always return the original email text (as shown above), so that your input text does not mysteriously change.