We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Validating Roman Numerals
Validating Roman Numerals
+ 1 comment regex_pattern = r"^(M){0,3}(CM)?(D)?(CD)?(C){0,3}(XC)?(L)?(XL)?(X){0,3}(IX)?(V)?(IV)?(I){0,3}$"
Here, only M, C, X and I can repeat at most 3 times, others can occur 0 or 1 times
+ 0 comments At first I came up with this:
regex_pattern = r"^(?!$)(M{1,3})?(CD|CM|D?C{1,3})?(XL|XC|L?X{1,3})?(IV|IX|V?I{1,3})?$"
But I see it can be done like this as well:
regex_pattern = r"^(?!$)M{0,3}(CD|CM|D?C{0,3})(XL|XC|L?X{0,3})(IV|IX|V?I{0,3})$"
Or even this way
regex_pattern = r"^(?!$)M{,3}(C[DM]|D?C{,3})(X[LC]|L?X{,3})(I[VX]|V?I{,3})$"
+ 2 comments Not everyone in every country is familiar with Roman Numerals though..
+ 0 comments The post about Validating Roman Numerals is intriguing! I love exploring various numeral systems and their validation techniques. By the way, if you're interested in cybersecurity and want to learn more about click here, they offer excellent resources to enhance your skills. Keep up the fascinating discussions!
+ 0 comments Dumbest test so far.
regex_pattern = r"^(M{0,3})(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$"
Load more conversations
Sort 180 Discussions, By:
Please Login in order to post a comment