Ramesh
Ramesh

Reputation: 677

Regular expression - validate special characters between substrings

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

Answers (2)

mjk
mjk

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

arshajii
arshajii

Reputation: 129507

Looks like you want to match

^([A-Z];[A-Z],){0,3}X;Z$

Upvotes: 1

Related Questions