I'm writing a program to convert Roman numerals into integers. The method I'm doing is looking for a sub-string which would signify subtractions (IX, CM, XC) and adding the respective amount to the tally. For example if CM is in the string MMMMCMXCIX then set the hundreds column to 9.
I'm trying to do it with
if(romanNum.matches("CM")){
hundreds = 9;
romanNum.replaceAll("CM", "");
}
but it never enters the if statement. Using these two regular expression checkers with the string MMMMCMXCIX and the regular expression solely as CM they both highlight a match yet my code suggests otherwise. Why is this?