Reputation: 677
I want to validate the special characters in a string. example "A;B,C;D,E;F,G;H" it means that "A;B" is a pair and "C;D" is next pair etc.. pairs are separated by "," So I need to validate this string should be same as above and should not start/end with "," and last pair should be "X;Y" and maximum 4 pairs. Can any one help me?
Upvotes: 2
Views: 147
Reputation: 541
Try: ^([A-z];[A-z],){0,3}X;Y$
.
This assumes an anchored string consisting of pairs made up of single alphabetic characters separated by a ;
, with pairs separated by a ,
. The last pair must always be X;Y
and there can be between 0 and 3 pairs before that.
Upvotes: 0