If I have a string a = I,II,III,IV,V,VI,VII,VIII
How can I use pattern to check if my input string matches any of these roman numbers?
Or is there any easier way to do so?
If I have a string a = I,II,III,IV,V,VI,VII,VIII
How can I use pattern to check if my input string matches any of these roman numbers?
Or is there any easier way to do so?
String pattern="^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$";
String input="VIII";
if(input.matches(pattern)){
System.out.println("true");
}else{
System.out.println("false");
}
How do you match only valid roman numerals with a regular expression?