Re: Assigning pattern matches to an array
- From: "Graham Stow" <graham@xxxxxxxxxxxx>
- Date: Sun, 31 Dec 2006 09:40:47 -0000
"DJ Stunks" <DJStunks@xxxxxxxxx> wrote in message news:1167521340.903496.86600@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Graham Stow wrote:Using the above line of
"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
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
- Follow-Ups:
- Re: Assigning pattern matches to an array
- From: Gunnar Hjalmarsson
- Re: Assigning pattern matches to an array
- References:
- Assigning pattern matches to an array
- From: Graham Stow
- Re: Assigning pattern matches to an array
- From: Uri Guttman
- Re: Assigning pattern matches to an array
- From: Graham Stow
- Re: Assigning pattern matches to an array
- From: DJ Stunks
- Re: Assigning pattern matches to an array
- From: Graham Stow
- Re: Assigning pattern matches to an array
- From: DJ Stunks
- Assigning pattern matches to an array
- Prev by Date: FAQ 4.53 How do I manipulate arrays of bits?
- Next by Date: Re: Assigning pattern matches to an array
- Previous by thread: Re: Assigning pattern matches to an array
- Next by thread: Re: Assigning pattern matches to an array
- Index(es):