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,N N",regex) match
if Regex.Match("BB,,JJ,LL,NN" ,regex) no match
thanks
if Regex.Match("BB,KK,JJ,LL,N
if Regex.Match("BB,,JJ,LL,NN"
thanks
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
BB,SS,II,JJ that is OK but not
BB,,MM,YY,LL since in the second place there is no value
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Alternative to regular expressions:
string[] = value.Split(',');
if (string[1] == "KK")
Bob
string[] = value.Split(',');
if (string[1] == "KK")
Bob
^[A-Z][A-Z],KK