471,315 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

multiple rejection

Hi everyone,

What I'm trying to do is, to match all the countries in a list, except
US and CANADA which is (CA).

I tried a lot, but none of mine worked at all. I'm new to regular
expressins and I looks completely none sense for me. I need this for
work ASAP.

Thanks everyone.

I was starting with this: [^US]|[^CA]. But as I was told after, that
matches soemthing weird, like Not U or Not S or not C or not A =\
bassically it matches everything =)

I need to match ^US AND ^CA, basically I want to exclude this to
countries.

Thanks a lot,

Alexander

Dec 24 '05 #1
1 1037
KJ
Try these:

string s1 = "CA";
string s2 = "FU";

if (Regex.Match(s1, "(US|CA)").Success)
{
Console.WriteLine("Country code '" + s1 + "' not ok.");
}

if (!Regex.Match(s2, "(US|CA)").Success)
{
Console.WriteLine("Country code '" + s2 + "' ok.");
}

// OR

if (Regex.Match(s1, "(?!(US|CA))").Success)
{
Console.WriteLine("Country code '" + s1 + "' not ok.");
}

if (Regex.Match(s2, "(?!(US|CA))").Success)
{
Console.WriteLine("Country code '" + s2 + "' ok.");
}

Dec 24 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Rolf Wester | last post: by
reply views Thread by Raymond Arthur St. Marie II of III | last post: by
66 posts views Thread by Darren Dale | last post: by
6 posts views Thread by Ben Hallert | last post: by
22 posts views Thread by Matthew Louden | last post: by
14 posts views Thread by Mattia | last post: by
35 posts views Thread by keerthyragavendran | last post: by
reply views Thread by JPabich | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.