------------------------------------------------------------------------------- Roman Numerials A system of representing numbers that really does date back to the ancient Roman empire. It was widely used, until the introduction of Arabic Numbers, which we use today. ------------------------------------------------------------------------------- Basic rules. Initially extracted from book "Dive Into Python 3", Chapter 5. Regular Expressions https://diveintopython3.problemsolving.io/regular-expressions.html I = 1 V = 5 X = 10 L = 50 C = 100 D = 500 M = 1000 The following are some general rules for constructing Roman numerals: * Sometimes characters are additive. I is 1, II is 2, and III is 3. VI is 6 (literally, "5 and 1"), VII is 7, and VIII is 8. * The tens characters (I, X, C, and M) can be repeated up to three times. At 4, you need to subtract from the next highest fives character. You can't represent 4 as IIII; instead, it is represented as IV ("1 less than 5"). 40 is written as XL ("10 less than 50"), 41 as XLI, 42 as XLII, 43 as XLIII, and then 44 as XLIV ("10 less than 50, then 1 less than 5"). * Sometimes characters are... the opposite of additive. By putting certain characters before others, you subtract from the final value. For example, at 9, you need to subtract from the next highest tens character: 8 is VIII, but 9 is IX ("1 less than 10"), not VIIII (since the I character can not be repeated four times). 90 is XC, 900 is CM. * The fives characters can not be repeated. 10 is always represented as X, never as VV. 100 is always C, never LL. Ditto for D * Roman numerals are read left to right, so the order of characters matters very much. DC is 600; CD is a completely different number (400, "100 less than 500"). CI is 101; IC is not even a valid Roman numeral (because you can't subtract 1 directly from 100; you would need to write it as XCIX, "10 less than 100, then 1 less than 10"). Is it a roman numerial? pattern = '^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$' NOTE: The empty string will also match, though zero does not exist in Roman Numerials. -------------------------------------------------------------------------------