What should be the regular expression to match a repetitive pattern like:
AA12/AA/12/BC
A/BC/CD/8
A1/1/X/7
Where the first character must be an alphabet, followed by any number of alphanumeric character, followed by the pattern “/X” repeated one or more times where X is alphanumeric character or multiple alphanumeric characters, and at least one repetition should contain a digit.
Valid patterns:
A/B/C/D/1
A/1234/XYSX
PQ123/1
AB/CD1/PQ
Invalid Patterns:
12/AB/34
AB/CD/XY
AB/CD
So far I have come up with :
[A-Za-z]\w*(/\w*[0-9]\w*)+
Which basically says that the later repetitive part should contain a digit, which is not correct as it is fine if only one repetitive part contains a digit..
Can any body help please?
Though certainly not the most beautiful solution, here is one possibility:
Note that I added in two instances of
(/\w+)*. Basically I’m just adding in “there can be more occurrences of slash-alphanum that don’t require a digit”.