• + 1 comment
    # Make the regex intent clearer and allow use of named groups for debug
    
    import re
    start = r"^"
    thousands = r"(?P<thousands>M{0,3})"
    hundreds = r"(?P<hundreds>CM|CD|(D{0,1}C{0,3}))"
    tens = r"(?P<tens>XC|XL|(L{0,1}X{0,3}))"
    units = r"(?P<units>IX|IV|(V{0,1}I{0,3}))"
    end = r"$"
    regex_pattern = rf"{start}{thousands}{hundreds}{tens}{units}{end}"	 # Do not delete 'r'.