Matching Character Ranges
Matching Character Ranges
+ 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.
+ 2 comments a0$?ZWe for this it should be true but its showing expected output is showing false
+ 1 comment question details isn't complete
It doesn't till that S must start at first index of line!
+ 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?
[deleted]Challenge Author + 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
Sort 73 Discussions, By:
Please Login in order to post a comment