Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Email addresses and regex's

by philth (Initiate)
on Jul 22, 2001 at 07:05 UTC ( [id://98754]=perlquestion: print w/replies, xml ) Need Help??

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

I have an email auto-responder thingy I'm trying to write. Now I have found ALOT of information on validating email addresses but not how to extract an address (if it exists) from an arbitrary line of text.

I started writing a regular expression to do this, but kept on writing ones that simply validate (sorta) the address or return chunks of it.

How can I get the entire addrss?

Replies are listed 'Best First'.
Re: Email addresses and regex's
by wog (Curate) on Jul 22, 2001 at 07:09 UTC
    Try the Email::Find module, prehaps.

    update: You say you are writing an auto-responder, and thus I think you won't need to search for an email adresses in completely arbitrary text. In that case Mail::Address and (possibly) Mail::Header and Email::Valid should be enough to (probably more easily and reliabily) do what you need.

      Hi, a few weeks ago I've taken over maintainance of Email::Find from Michael. If you guys have any requests or suggestions, don't hesitate to tell me. Thanks.

      --
      Tatsuhiko Miyagawa
      miyagawa@cpan.org

Re: Email addresses and regex's
by footpad (Abbot) on Jul 22, 2001 at 07:23 UTC

    If you want completely accurate results--and want to understand them--please get a copy of Mastering Regular Expressions. The code is online, but the commentary--and difficulties--associated with validating email addresses are presented very clearly.

    It's not a trivial process and the discussion leading up to it is worth the purchase price, for it applies to Perl and many other products as well.

    YMMV, of course...

    --f

Re: Email addresses and regex's
by AidanLee (Chaplain) on Jul 22, 2001 at 07:08 UTC

    I have seen many times that there is no *easy* way to write a regex to match the full specification for an email address. I do know there is at least one module on CPAN that does validation, it might be a place to start.

    update: try this node for starters.
Re: Email addresses and regex's
by HyperZonk (Friar) on Jul 23, 2001 at 07:51 UTC
    Plenty of good advice already appears above. For the sake of completeness, though, I thought I would note that there is another module, Mail::CheckUser, that is also available. This nifty little module will even make sure that a mail server exists and attempt to verify the user's existence on that server. You can run any subset of the module's checking routines that you wish. See the module docs for more info, including important warnings.

    -HZ
Re: Email addresses and regex's
by philth (Initiate) on Jul 22, 2001 at 09:49 UTC
    Thanks guys! :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://98754]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2025-05-24 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.