Parsing all e-mail addresses from a document - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Parsing all e-mail addresses from a document

HackmanCHackmanC Posts: 441Member
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.
[red]Good luck![/red]
[blue]Hackman[/blue]

Comments

  • XfactorXfactor Posts: 343Member
    : 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.
    : [red]Good luck![/red]
    : [blue]Hackman[/blue]
    :

    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:
    [code]
    if ($email_address =~ /(@.*@)|(..)|(@.)|(.@)|(^.)/) {
    print "Email is invalid
    ";
    }
    elsif ($email_address =~ /^.+[_*]@([?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,4}|[0-9]{1,4})(]?)$/) {
    print "Email is valid
    ";
    }
    [/code]
  • HackmanCHackmanC Posts: 441Member
    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.
    : : [red]Good luck![/red]
    : : [blue]Hackman[/blue]
    : :
    :
    : 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:
    : [code]
    : if ($email_address =~ /(@.*@)|(..)|(@.)|(.@)|(^.)/) {
    : print "Email is invalid
    ";
    : }
    : elsif ($email_address =~ /^.+[_*]@([?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,4}|[0-9]{1,4})(]?)$/) {
    : print "Email is valid
    ";
    : }
    : [/code]
    :

    [red]Good luck![/red]
    [blue]Hackman[/blue]

  • JonathanJonathan Posts: 2,914Member
    : 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 =~ /([w-.]+@[w-.]+.w+)/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.");

  • HackmanCHackmanC Posts: 441Member
    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 =~ /([w-.]+@[w-.]+.w+)/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.");
    :
    :

    [red]Good luck![/red]
    [blue]Hackman[/blue]

  • XfactorXfactor Posts: 343Member
    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
Sign In or Register to comment.