Regular expressions

I am using  Regex.Match(value,regex) and value is a string of this format value="BB,KK,JJ,LL,NN". I want a regular expression regex that will identify if the second element 'KK' is in the string or not.
if Regex.Match("BB,KK,JJ,LL,NN",regex)  match
if Regex.Match("BB,,JJ,LL,NN",regex)  no match

thanks
Kan64Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amit_gCommented:
Try

^[A-Z][A-Z],KK
Kan64Author Commented:
The KK could be anything like JJ in the second place. I just want to make sure there is a value. That is there must be some alphanumeric characters between the comas. Like
 BB,SS,II,JJ that is OK but not
 BB,,MM,YY,LL since in the second place there is no value
Thanks
amit_gCommented:
^[A-Z][A-Z],[A-Z][A-Z]

should do it.
Fernando SotoRetiredCommented:
Hi Kan64;

The following code will find if the second value is missing

      Match m;
      string SecondValue = "";
      m = Regex.Match(InputStr, "^[a-zA-Z0-9]{2},,");
      if (m.Success)
      {
              // The second value is missing
      }

or if you want m.Success to happen when you have a second value then do this

      Match m;
      string SecondValue = "";
      m = Regex.Match(InputStr, "^([a-zA-Z0-9]{2},){2}");
      if (m.Success)
      {
              // The second value is not missing
      }

or if you want the second value in the string then do this

      Match m;
      string SecondValue = "";
      m = Regex.Match(InputStr, "^[a-zA-Z0-9]{2},(?<Second>[a-zA-Z0-9]{2}),");
      if (m.Success)
      {
              // The second value is not missing
                SecondValue = m.Groups["Second"].Value;
      }

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
Alternative to regular expressions:

  string[] = value.Split(',');

  if (string[1] == "KK")

Bob
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.