Re: Assigning pattern matches to an array




"DJ Stunks" <DJStunks@xxxxxxxxx> wrote in message news:1167521340.903496.86600@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Graham Stow wrote:
"DJ Stunks" <DJStunks@xxxxxxxxx> wrote in message
news:1167506565.933525.68510@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Graham Stow wrote:
push(@matches, $line=~/\b\w+@\w+\b/g); did it for me
The pattern doesn't match an email address, but I can work on that...

well, for one thing, the \w metacharacter doesn't match a literal .

don't roll your own email address regexp.

perldoc Email::Address

Emaill::Address doesn't grab me
Done a quick test between
use Email::Address
push(@matches, Email::Address->parse($line));
and
push(@matches, $line=~/\b[.-\w]*@[-\w]*\.+[-\w]*\.*[-\w]*\b/g);
The latter pulled up a number of correct email address, while the former
pulled these up plus other stuff that weren't true email addresses

try (untested):

push @matches, map { $_->address } Email::Address->parse($line);

-jp

Using the above line of
push @matches, map { $_->address } Email::Address->parse($line);
on a directory including one 'Word' document containing four email addresses, I got the output:-
ian@xxxxxxxxxxx

ian@xxxxxxxxxxx}}}{\f1\fs20\lang1033\langfe1033\langnp1033

brian@xxxxxxxxx

brian@xxxxxxxxx}}}{\f1\fs20\lang1033\langfe1033\langnp1033

edward_woodward@xxxxxxxxxxxxxxxxxxxxx

oodward@xxxxxxxxxxxxxxxxxxxxx}}}{\f1\fs20\lang1033\langfe1033\langnp1033

roger.smallpiece@xxxxxxxxxx

roger.smallpiece@xxxxxxxxxx}}}{\f1\fs20\lang1033\langfe1033\langnp1033

8 matches

Using 'my' line of
push(@matches, $line=~/\b[.-\w]*@[-\w]*\.+[-\w]*\.*[-\w]*\b/g);
on a directory including one textfile and one 'Word' document, both containing a few email addresses, I go the output:-
ian@xxxxxxxxxxx

brian@xxxxxxxxx

edward_woodward@xxxxxxxxxxxxxxxxxxxxx

oodward@xxxxxxxxxxxxxxxxxxxxx

roger.smallpiece@xxxxxxxxxx

5 matches

Interestingly neither are perfect (both can't resolve edward_woodward@ correctly), but at least mine doesn't produce the additional characters beyond the email address that using Email::Address produces