SPUG: Regex that matches everything except a specific string
John Subaykan
cansubaykan at hotmail.com
Thu Nov 6 13:28:07 CST 2003
If you have are scanning entries like this where the string you are matching
begins with the same thing (like 'address:' or 'To: ')
address:richard at richard-anderson.org
address:someone at somewhere.com
address:bad at e.mail
address:junk-junk-junk
in this case, you can do:
/address:(?!richard\@richard-anderson.org)/
if you are matching only the email address part, I'm not sure how to use
this method (negative lookahead or lookbehind.
----Original Message Follows----
From: "Richard Anderson" <richard at richard-anderson.org>
To: <spug-list at mail.pm.org>
Subject: SPUG: Regex that matches everything except a specific string
Date: Thu, 6 Nov 2003 09:16:12 -0800
I am trying to feed a regular expression to a mail processing program that
matches every string except a specific string. For example, I want a regex
that does not match richard at richard-anderson.org but matches any other
string. If I were writing a Perl program, I would just do this:
if ($address !~ /^richard\@richard-anderson\.org$/) { print "Spam\n" }
but I am not able to modify the source code of the program I am using.
I haven't been able to do this using the complement metacharacter (^). I'd
accept a solution that matches anything except an anagram of
richard at richard-anderson.org
P.S. This is actually a Python regex, but Python's regexes are very similar
to Perl's regexes.
Richard Anderson
richard at richard-anderson.org
www.richard-anderson.org
Richard.Anderson at raycosoft.com
www.raycosoft.com
_____________________________________________________________
Seattle Perl Users Group Mailing List
POST TO: spug-list at mail.pm.org http://spugwiki.perlocity.org
ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
MEETINGS: 3rd Tuesdays, U-District, Seattle WA
WEB PAGE: http://www.seattleperl.org
_________________________________________________________________
MSN Messenger with backgrounds, emoticons and more.
http://www.msnmessenger-download.com/tracking/cdp_customize
More information about the spug-list
mailing list