You can use a capture group to "remember" what the separator was in the first case, and ensure that the other cases also use it.
The final regex is: d{4}([s-])*d{4}1*d{4}1*d{4}
The ()
around the first [s-]
start the capture group; the 1
later on indicates to use the same value as was previously captured.
See it in action here https://regexr.com/5l74g
Edit: per the comments, a better solution might be
d{4}([s-]?)d{4}1d{4}1d{4}
, depending on what exactly your requirements are. This one ensures that -
s and
s are not mixed, and also that there is only 0 or 1 separators.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…