From owner-freebsd-questions Wed Jan 2 10:17:35 2002 Delivered-To: freebsd-questions@freebsd.org Received: from out002pub.verizon.net (out002pub.verizon.net [206.46.170.102]) by hub.freebsd.org (Postfix) with ESMTP id DD00237B405 for ; Wed, 2 Jan 2002 10:17:24 -0800 (PST) Received: from verizon.net ([199.171.52.20]) by out002pub.verizon.net with ESMTP ; id g02IHAd04542 Wed, 2 Jan 2002 12:17:10 -0600 (CST) Message-ID: <3C334E58.7050905@verizon.net> Date: Wed, 02 Jan 2002 13:15:52 -0500 From: Simon Morton Reply-To: smorton@acm.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.7) Gecko/20011221 X-Accept-Language: en,pdf,zh-CN,de-DE,zh-TW,zh, zh- MIME-Version: 1.0 To: doug@safeport.com Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Regex Question - email matching References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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