I just started toying around with regex. I've looked at Google's Python regex howto and Python's regex howto as well as other similar questions like Convert a string containing a roman numeral to integer equivalent and How do you match only valid roman numerals with a regular expression?, but I am still confused.
My code:
user = str(input("Input the Roman numeral: "))
characters = "I", "V" "X", "L", "C", "D", "M"
values = 1, 5, 10, 50, 100, 500, 1000
def numerals(match):
return str(user(match.group(0)))
s = str(input("Input the Roman numeral: "))
regex = re.compile(r'\b(?=[MDCLXVI]+\b)M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V? I{0,3})\b')
print regex.sub(numerals, s)
The last two lines are from the first link. I don't fully understand regex = re.compiler...
and am wondering if it actually converts the user's roman numerals to integers?
Thanks in advance