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
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Regex
  3. Character Class
  4. Matching Character Ranges
  5. Discussions

Matching Character Ranges

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 73 Discussions, By:

votes

Please Login in order to post a comment

  • scott79
    7 years ago+ 1 comment

    The listed task is as stated: S must be of length, greater than or equal to 5. First character should be a lowercase alphabet. Second character should be a positive digit. Third character should not be a lowercase alphabet. Fourth character should not be a uppercase alphabet. Fifth character should be an uppercase alphabet.

    If we break this down we can see, by the first statement the string can be greater than or equal to 5. This indicates once you have the core regex you can simply add '.*' to match anything following it (if anything continues to follow) First char => ^[a-z] Sec char => [1-9] Third char => [^a-z] Fourth char => [^A-Z] Fifth char => [A-Z]

    So, with this we have: ^[a-z][1-9][^a-z][^A-Z][A-Z].* We put the .* since the statement said the string length can be at least 5 characters long but it could be more.

    13|
    Permalink
  • DarthVader93
    7 years ago+ 2 comments

    a0$?ZWe for this it should be true but its showing expected output is showing false

    8|
    Permalink
  • Khwarizm
    6 years ago+ 1 comment

    question details isn't complete

    It doesn't till that S must start at first index of line!

    2|
    Permalink
  • RA1911003010513
    9 months ago+ 0 comments

    Test case 4 is q9$?WWe and expected output is false. Can anyone tell me how is it not matching the given regex pattern?

    1|
    Permalink
  • [deleted]Challenge Author 4 years ago+ 1 comment

    My java solution:

    ^[a-z][1-9][^a-z][^A-Z][A-Z].*{5,}
    

    Though I find the editorial solution to be more elegant

    1|
    Permalink
Load more conversations

Need Help?


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