Regex for finding email addresses inside text file

D

Doug Wells

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
 
T

Tad McClellan

Doug Wells said:
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.
 
J

Jürgen Exner

Doug said:
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
 
T

terry l. ridder

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.
 
T

Tore Aursand

Doug said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top