Re: Assigning pattern matches to an array



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

.



Relevant Pages

  • Re: Assigning pattern matches to an array
    ... Graham Stow wrote: ... 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. ... perldoc Email::Address ...
    (comp.lang.perl.misc)
  • Re: Assigning pattern matches to an array
    ... 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. ... Graham ...
    (comp.lang.perl.misc)
  • Re: Regex puzzler!
    ... Your small error is forgetting that the question mark is a ... metacharacter. ... See the perlre documentation. ... Your medium error is misusing the syntax of the m// pattern match ...
    (perl.beginners)
  • [PS] User Guide p.79
    ... It matches 0 or 1 occurences of the preceding character or ... pattern, not as stated. ... Also the + metacharacter has been, I assume inadvertently, omitted ...
    (microsoft.public.windows.server.scripting)