Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegEx Question - "NOT IN" Possible?

Status
Not open for further replies.

MikeBronner

Programmer
May 9, 2001
756
US
Hi all,

I've worked myself in a bit of a pickle here, and can't quite seem to figure this one out.

Requirements: the regex must not match the string if a phrase that is being tested for is in it.

What I am Doing: I am looking at email headers and directing them appropriately. If my email does not appear in the TO string of the email, I will route it to the spam box.

My email filtering can use RegExs. By default all my mail goes into my inbox, however, I want to get all mail that doesn't have my email address in the header and route it to the spam box.
To do this I was thinking of using something similar to the "NOT IN" functionality in SQL, but can't quite figure it out:

Here are a few examples:
test@email.com;myemail@myserver.com;someyahoo@test.com
This one should not be sent to the spam bin. However, the next one should:
test@email.com;someyahoo@test.com
The regex I have so far is this:
Code:
[^(.*(vmware\.com\@emmgee\.com).*)]
Unfortunately this still matches on email addresses that could be spam, i.e. that don't belong to me.

Any ideas?

Thanks a bunch!
 
here's my proposal:

Code:
<script type="text/javascript"><!--

var re = /youremail\@gmail\.com/i;

var s = "test@email.com;myemail@myserver.com;someyahoo@test.com;youremail@gmail.com";
document.write( s + ": " + re.test(s) + "<br />");
var t = "test@email.com;youremail@gmail.com;myemail@myserver.com;someyahoo@test.com;";
document.write( t + ": " + re.test(t) + "<br />");
var u = "youremail@gmail.com;test@email.com;myemail@myserver.com;someyahoo@test.com;";
document.write( u + ": " + re.test(u) + "<br />");
var v = "youremail@gmail.com";
document.write( v + ": " + re.test(v) + "<br />");
var w = "test@email.com;myemail@myserver.com;someyahoo@test.com;";
document.write( w + ": " + re.test(w) + "<br />");
var x = "test@email.com;myemail@myserver.com;someyahoo@test.com;yOUremail@GmaIL.com";
document.write( x + ": " + re.test(x) + "<br />");

//--></script>



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
The problem is that I don't have the capability to do this in code (I couldn't find a regex forum per se, so I thouhgt this might be a fitting place). I see what you are saying, however, I am restricted to use only reular expressions, no code. :|

Take Care,
Mike
 
[tt]
//any valid email valiating pattern can be more or less sophisticated, it is up to you.
var rx_email=="[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*"

//the spam filter characteristic string
var rx_spamfilter=="(?=myemail@myserver\\.com;)"

//the complete validating pattern
var rx_pattern="^"+rx_email+";"+rx_spamfilter+rx_email+"$"

//this is the desired regexp
var rx=new RegExp(rx_pattern);

var s;
s="test@email.com;myemail@myserver.com;someyahoo@test.com";
alert(s+"\n"+rx.test(s)); //would return true
s="test@email.com;someyahoo@test.com";
alert(s+"\n"+rx.test(s)); //would return false
[/tt]
 
Amendment
Upon re-reading, I don't know why the equal sign doubled up! The two lines should be read correspondingly like this obviously.
[tt]
//any valid email valiating pattern can be more or less sophisticated, it is up to you.
var rx_email="[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*"

//the spam filter characteristic string
var rx_spamfilter="(?=myemail@myserver\\.com;)"
[/tt]
Separating into parts are just for illustration. If the pattern is to be typed in into some interface textbox, one joins them together manually is what it is meant.
 
Thanks for you insight, tsuji! I will try it out and report back. :)

Take Care,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top