Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Tim Watts Newsgroups: comp.os.linux.misc Subject: Re: Script to parse a text file and extract unique email addresses Date: Mon, 29 Sep 2014 07:40:23 +0100 Lines: 33 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net NUtBQJO8WtguHStRwUjkGQ9y9rX0FQwI7F0WVNWf28Qn3OxYvG X-Orig-Path: squidward.local.dionic.net!not-for-mail Cancel-Lock: sha1:n1i8TQw9rEeLG20eYYf991w1cvM= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: Xref: csiph.com comp.os.linux.misc:12185 On 29/09/14 01:17, Mladen Gogala wrote: > #!/usr/bin/env perl > use warnings; > use strict; > my %EMAILS; > while (<>) { > if (/([a-z0-9.-]+\@[a-z0-9.-]+)/i) { > if ( !defined( $EMAILS{$1} ) ) { > $EMAILS{$1} = 1; > } > else { next; } > } > else { next; } > } > foreach my $addr ( sort keys %EMAILS ) { > print "$addr\n"; > } The domain part of the regex is fine (excepting new fangled unicode domains). However the local part (before the @) is lacking a large set of legal characters. http://en.wikipedia.org/wiki/Email_address#Local_part (because it's easier than finding *that* particular RFC). In particular _ and + are quite common I often find web script programmers make serious errors as I try to use one of my email addresses and it barfs.