multiple rejection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aragorn_USA

    #1

    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

  • KJ

    #2
    Re: multiple rejection

    Try these:

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

    if (Regex.Match(s1 , "(US|CA)").Succ ess)
    {
    Console.WriteLi ne("Country code '" + s1 + "' not ok.");
    }

    if (!Regex.Match(s 2, "(US|CA)").Succ ess)
    {
    Console.WriteLi ne("Country code '" + s2 + "' ok.");
    }

    // OR

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

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

    Comment

    Working...