Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 02 Jan 2002 13:15:52 -0500
From:      Simon Morton <simon.morton@verizon.net>
To:        doug@safeport.com
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Regex Question - email matching
Message-ID:  <3C334E58.7050905@verizon.net>
References:  <Pine.BSF.4.21.0201021227430.41813-100000@pemaquid.safeport.com>

next in thread | previous in thread | raw e-mail | index | archive | help
doug@safeport.com wrote:

> I know this is impossible in general. I am looking for something that matches
> the normal me@domain.tld. What I settled on so far is (in perl):
> 
> 	\w+\@\w+\.\w+
> 
> This is cool in that it is short, it matches things like
> first.last@host.domain.tld. It unfortunately also matches me@name@domain.tld
> which I do not believe is valid. So my question: is there an *easy* way to
> require exactly one "@".


How about the following?

#/usr/bin/perl

my $email = shift;

if ( $email =~ /^([\w\.\-]+)\@([\w\.\-]+)\.([[:alpha:]]+)$/ ) {
   print "name   = $1\n";
   print "domain = $2\n";
   print "tld    = $3\n";

} else {
   print "Invalid email address\n";
}

exit;


HTH
simon

-- 
http://www.SimonMorton.com
smorton at acm dot org
\rm -rf /bin/laden


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C334E58.7050905>