multiple rejection

  • Thread starter Thread starter Aragorn_USA
  • Start date Start date
A

Aragorn_USA

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
 
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.");
}
 
Back
Top