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.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Matching Character Ranges
You are viewing a single comment's thread. Return to all comments →
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.