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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Python
  3. Regex and Parsing
  4. Validating Roman Numerals
  5. Discussions

Validating Roman Numerals

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 180 Discussions, By:

recency

Please Login in order to post a comment

  • abhishekk962
    1 month ago+ 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|
    Permalink
  • medyk_pawel
    3 months ago+ 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})$"
    
    0|
    Permalink
  • gondor32
    3 months ago+ 2 comments

    Not everyone in every country is familiar with Roman Numerals though..

    4|
    Permalink
  • r8353030
    5 months ago+ 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!

    -4|
    Permalink
  • ptrerov
    5 months ago+ 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})$"

    -4|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy