I came up with this regex:
(?:[0-9]{4}-([0-9]{4}|[?]))+
for this text:
1993-2000,2004-?
The regex to capture on block = [0-9]{4}-([0-9]{4}|[?])
I have variations like:
1993-? 1993-2000 1993-2000,2004-? 1993-2000,2004-2010
and so on.
My regex captures the blocks [1993-2000]
and [2004-?]
, but not the comma.
What I find hard is to declare the comma should be mandatory for the second, third, etc. occurrences.
So what should not be allowed is:
1993-2000, 1993-20002007-? ?-2000
Possibly this could be allowed to0: 1993-2000,2004,2007,2010-?
Can someone help me get this last understanding about a conditional comma for second and followup occurrences?
I found this regex which I adapted a bit:
^([0-9]{4}(-([0-9]{4}|[?]))?)(,([0-9]{4}(-([0-9]{4}|[?]))?))*$
Seems to do the trick, but is this the best version?