CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
pattern match

 



martin barlow
New User

Apr 14, 2005, 5:25 PM

Post #1 of 4 (4392 views)
pattern match Can't Post

The pattern will contain one email address.

Emails should not be matched unless:
They are from a certain domain (say domain.com)
AND not from a two specific emails (say john@domain.com and david@domain.com)

whatever@whatever.com (not match)
whatever@domain.com (match)
john@domain.com (not match)
david@domain.com (not match)

I am sure there is any easy way, but its a bit beyond my regular expression skills! Thanks for any solutions.Cool


davorg
Thaumaturge / Moderator

Apr 17, 2005, 9:54 AM

Post #2 of 4 (4382 views)
Re: [martin barlow] pattern match [In reply to] Can't Post

It's probably easier in this case to split the email address into local part and domain name (by splitting on @) and then doing string comparison.


Code
#!/usr/bin/perl 

use strict;
use warnings;

my %match_domain = ('domain.com' => 1);
my %nomatch_name = (john => 1,
david => 1);

while (<DATA>) {
chomp;
my ($local, $domain) = split /@/;

print "$_ - ";
if ($match_domain{$domain} and not $nomatch_name{$local}) {
print "Match\n";
} else {
print "No Match\n";
}
}

__DATA__
whatever@whatever.com
whatever@domain.com
john@domain.com
david@domain.com


Regexes aren't always the best solution to text matching problems :)

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


martin barlow
New User

Apr 20, 2005, 4:46 AM

Post #3 of 4 (4360 views)
Re: [davorg] pattern match [In reply to] Can't Post

Dave

I agree that the simple solution is often the best. Your solution is elegant. Unfortunately in my case i don't have access to proper PERL from the interface.

I need this for a CRM which allows me to specify PCRE's to match email addresses and deal with them accordingly.

I'll mull over this problem a bit longer......

Marty


(This post was edited by martin barlow on Apr 20, 2005, 4:49 AM)


martin barlow
New User

May 18, 2005, 10:05 PM

Post #4 of 4 (4037 views)
Re: [martin barlow] pattern match [In reply to] Can't Post

/^(?!(david|john)\@)(.)+\@domain\.com$/i

look good?


(This post was edited by martin barlow on May 18, 2005, 10:06 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives