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

Monks,

I found this node Common Regex's because I need a regular expression to match any email address. I tried using the 6000 character beast LeG0 recommends in the above node, but I received a bunch of error messages :
(ie. Backslash found where operator expected at ./whois.pl line 20, ne +ar "]\" (Missing operator before \?) Backslash found where operator expected at ./whois.pl line 20, near "0 +37\" (Missing operator before \?)<br><br> -----------About 30 more similar error's----------------------

I have two questions:

  1. Has an easier way been discovered to match an email address since this node was written? I would even settle for something that matches just 75% of the time. I will also need to capture this to $1. Not sure if this makes any difference.
  2. When I copied and paste this regex into my ssh terminal, I got a newline for each line break, so I manually joined the lines together with vi. Is there a way to copy and paste a long regex like this into my program without having to join all the lines afterwards.
I appreciate any help.

-Dru

Replies are listed 'Best First'.
Re: Matching any Email Address
by scain (Curate) on Sep 04, 2001 at 23:09 UTC
    CPAN is your friend. There are several modules for dealing with mail, take a look at 19_Mail_and_Usenet_News generally.

    Scott

    PS I was going to add more specific advice, but search.cpan.org is not responding :-/

Re: Matching any Email Address
by George_Sherston (Vicar) on Sep 04, 2001 at 23:29 UTC
    For the 75%- 95% match, try this
    m/\s*^<?[^@<>]+@[^@.<>]+(\.[^@.<>]+)+>?\s*$/
    which is what CGI::Validate uses for validating email addresses

    § George Sherston
Re: Matching any Email Address
by runrig (Abbot) on Sep 04, 2001 at 23:21 UTC
Re: Matching any Email Address
by TStanley (Canon) on Sep 05, 2001 at 04:19 UTC
    I also asked a similar question not so long ago, and I received many useful answers from it.

    TStanley
    --------
    There's an infinite number of monkeys outside who want to talk to us
    about this script for Hamlet they've worked out
    -- Douglas Adams/Hitchhiker's Guide to the Galaxy
Re: Matching any Email Address
by blakem (Monsignor) on Sep 04, 2001 at 23:17 UTC
    To answer your question on downloading code from the monastery, yes there is an easier way. If you bring the node up to the top, like so, you can use the 'd/l code' link at the bottom to grab only the stuff between <code> tags.

    -Blake