Perl

Moderators: Jonathan
Number of threads: 1236
Number of posts: 3605

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Parsing all e-mail addresses from a document Posted by HackmanC on 30 Sept 2004 at 2:58 PM
I had a program that loads a document. I want to get all email addresses from the document.

I need the regular expression to acomplish this task.
Good luck!
Hackman
Report
Re: Parsing all e-mail addresses from a document Posted by Xfactor on 30 Sept 2004 at 5:09 PM
: I had a program that loads a document. I want to get all email addresses from the document.
:
: I need the regular expression to acomplish this task.
: Good luck!
: Hackman
:

I'm not sure if there's any chance of invalid addresses but here's something to get you started. And I'm sure the more advanced regex guys will post their revisions:
if ($email_address =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/) {
         print "Email is invalid\n";
}
elsif ($email_address =~ /^.+[\_*]\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/) {
       print "Email is valid\n";
}

Report
Re: Parsing all e-mail addresses from a document Posted by HackmanC on 30 Sept 2004 at 11:12 PM
Thanks

--------------
: : I had a program that loads a document. I want to get all email addresses from the document.
: :
: : I need the regular expression to acomplish this task.
: : Good luck!
: : Hackman
: :
:
: I'm not sure if there's any chance of invalid addresses but here's something to get you started. And I'm sure the more advanced regex guys will post their revisions:
:
: if ($email_address =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/) {
:          print "Email is invalid\n";
: }
: elsif ($email_address =~ /^.+[\_*]\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/) {
:        print "Email is valid\n";
: }
: 

:

Good luck!
Hackman

Report
Re: Parsing all e-mail addresses from a document Posted by Jonathan on 4 Oct 2004 at 2:28 PM
: And I'm sure the more advanced regex guys will post their revisions:
Or maybe just a good way to extract all of the addresses and put them in an array with one line of code...

push @addrs, $1 while $text =~ /\b([\w\-\.]+\@[\w\-\.]+\.\w+)\b/g;

Where @addrs is an array to put the addresses in and $text is the text in the document.

XFactor's solutiion probably does fine, but figured I'd show off...uh...I mean, post how I'd do it.

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Report
Re: Parsing all e-mail addresses from a document Posted by HackmanC on 11 Oct 2004 at 10:20 AM
Nice one, I will use this too... thanks.

: : And I'm sure the more advanced regex guys will post their revisions:
: Or maybe just a good way to extract all of the addresses and put them in an array with one line of code...
:
: push @addrs, $1 while $text =~ /\b([\w\-\.]+\@[\w\-\.]+\.\w+)\b/g;
:
: Where @addrs is an array to put the addresses in and $text is the text in the document.
:
: XFactor's solutiion probably does fine, but figured I'd show off...uh...I mean, post how I'd do it.
:
: Jonathan
:
: ###
: for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
: (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
: /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
:
:

Good luck!
Hackman

Report
Re: Parsing all e-mail addresses from a document Posted by Xfactor on 11 Oct 2004 at 7:45 PM
There are perl modules that also might be able to help you out. You can check out the module called MAIL::VRFY and it's located here.
http://search.cpan.org/~jkister/Mail-VRFY-0.51/VRFY.pm

Of course there are others but this can give you an idea if this is something you can use.

X



 

Recent Jobs