building on from this question, I have a problem extending my regex, which now looks like this:
String pattern= "(?:I[XV]|X[LC]|C[DM]|[XVLCDM])+";
String test="XM";
System.out.println(test.matches(pattern));
The allowable characters in my string are IVXLCDMAQT
XM currently returns true. But it should not because X can only precede L or C. How can I modify my current regex to prevent XM from returning true and also have the allowable characters in my string?
Update based on request: The precedence:
I can be followed only by X or V, X can only be followed by L or C, C can only be followed by D or M. The rest of the letters don't matter.
Thus XM should return false. However, currently it doesn't