Link to home
Start Free TrialLog in
Avatar of Kan64
Kan64

asked on

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
Avatar of amit_g
amit_g
Flag of United States of America image

Try

^[A-Z][A-Z],KK
Avatar of Kan64
Kan64

ASKER

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
SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Alternative to regular expressions:

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

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

Bob