Sort by

recency

|

199 Discussions

|

  • + 0 comments
    regex_pattern = r"(?!.*(I{4}|V{2,}|X{4}|L{2,}|C{4}|D{2,}|M{4})).*$"
    
    import re
    print(str(bool(re.match(regex_pattern, input()))))
    
  • + 0 comments
    regex_pattern = r"^(M{0,3})(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$"
    import re
    print(str(bool(re.match(regex_pattern, input()))))
    
  • + 0 comments

    Regular Expression for this problem

    r"^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$"
    
  • + 0 comments

    regex_pattern = r"^(?!.*(I{4}|V{2,}|X{4}|L{2,}|C{4}|D{2,}|M{4})).*$"

  • + 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'.