HackerRank Python - Validating Roman Numerals

You are given a string, and you have to validate whether it's a valid Roman numeral. If it is valid, print True. Otherwise, print False. Try to create a regular expression for a valid Roman numeral.

  1. regex_pattern = r'M{0,3}(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[VX]|V?I{0,3})$' # Do not delete 'r'.
  2. import re
  3. print(str(bool(re.match(regex_pattern, input()))))

download android app