我有以下字符串:
str = "MMX Lions Television Inc"
我需要将其转换为:
conv_str = "2010 Lions Television Inc"
我有以下函数将罗马数字转换为其等效整数:
numeral_map = zip(
(1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1),
('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
)
def roman_to_int(n):
n = unicode(n).upper()
i = result = 0
for integer, numeral in numeral_map:
while n[i:i + len(numeral)] == numeral:
result += integer
i += len(numeral)
return result
我将如何re.sub
在这里获取正确的字符串?
(注意:我尝试使用regex
此处描述的内容:How do you match only valid roman numbers with a regular expression?但它不起作用。)