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

I need to get all "mailto" addresses. Is this correct??
if($variable =~ /mailto\:(.+?\@.+)/)

20030622 Edit by Corion: Changed title from Fetching email

Replies are listed 'Best First'.
Re: Grabbing e-mail addresses from a variable
by gellyfish (Monsignor) on Jun 20, 2003 at 11:20 UTC

    No that will only get the first one. You want something more like:

    my @addrs = ($data =~ /mailto:(.+?\@[^">\s]+)"?/g);
    (Only tested with very limited cases). But my vote would be to use HTML::LinkExtor in preference to some regex which is bound to fail under some circumstance.

    /J\
    
      Thanks, that works.
      I would like to notice that if after email address will be some character unlike from space - dot, comma, semicolon etc, than this character will be included into result.
            
      --------------------------------
      SV* sv_bless(SV* sv, HV* stash);
      
Re: Grabbing e-mail addresses from a variable
by Bilbo (Pilgrim) on Jun 20, 2003 at 11:28 UTC

    You haven't told it where to stop. Have you actually tried running this on an html file? Any text following the address will be added to the address. Assuming that you are extracting this from an html file you probably want to get all characters before a closing quote (").

A reply falls below the community's threshold of quality. You may see it by logging in.