Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Regex for finding email addresses inside text file (http://www.velocityreviews.com/forums/t890428-regex-for-finding-email-addresses-inside-text-file.html)

Doug Wells 01-27-2005 12:44 AM

Regex for finding email addresses inside text file
 
Can anyone help me with a regex that looks through an entire text file
which might have multiple email addresses in it, and writes those email
addresses out to a second file?

Thanks for the help
Doug

Tad McClellan 01-27-2005 02:08 AM

Re: Regex for finding email addresses inside text file
 
Doug Wells <doug@taperedsquare.com> wrote:

> Can anyone help me with a regex



Sure.

Show us the regex in question, and we will help you fix it.


> that looks through an entire text file
> which might have multiple email addresses in it, and writes those email
> addresses out to a second file?



Regexes do not read/write files.


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Jürgen Exner 01-27-2005 03:07 AM

Re: Regex for finding email addresses inside text file
 
Doug Wells wrote:
> Can anyone help me with a regex that looks through an entire text file
> which might have multiple email addresses in it, and writes those
> email addresses out to a second file?


You may want to read the FAQ "How do I check a valid mail address?".

While in theory using REs to identify email addresses may be possible, just
like parsing HTML no sane person would try to do it that way.

jue



terry l. ridder 01-27-2005 06:14 AM

Re: Regex for finding email addresses inside text file
 
On Thu, 27 Jan 2005, Doug Wells wrote:

> Can anyone help me with a regex that looks through an entire text file
> which might have multiple email addresses in it, and writes those email
> addresses out to a second file?
>


just to give you some idea of how difficult that would be consider for a
moment just how many top level domains there are.

hint: 200+
there are 247 ccTLD
from .ac - Ascension Island through .zw - Zimbabwe
consider the ccTLD .us
there are numerous 2nd-level sub domains. the 50 states and the numerous
terroritories.
then there are the generic TLDs.
..aero, .biz, .com, .coop, .info, .museum, .name, .net, .org, .pro,
..gov, .edu, .mil, and .int

to learn more please refer to http://www.iana.org and look under domain
name services.

this is a nontrivial task.

>
> Thanks for the help
> Doug
>


--
terry l. ridder ><>

Tore Aursand 01-27-2005 10:46 AM

Re: Regex for finding email addresses inside text file
 
Doug Wells wrote:
> Can anyone help me with a regex that looks through an entire text file
> which might have multiple email addresses in it, and writes those email
> addresses out to a second file?


Take a look at the Mail::Address module on CPAN. It will let you can
text for email addresses;

#!/usr/bin/perl
#
use strict;
use warnings;
use Mail::Address;

my $text = '...';
my @addresses = Mail::Address->parse( $text );

my %addresses;
foreach ( @addresses ) {
$addresses{ $_->address() }++;
}

The rest is up to you, as it really is very simple.


--
Tore Aursand <tore@aursand.no>
"Those people who think they know everything are a great annoyance to
those of us who do." (Isaac Asimov)


All times are GMT. The time now is 07:28 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.