Sort 73 Discussions, By:
Please Login in order to post a 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.
a0$?ZWe for this it should be true but its showing expected output is showing false
It doesn't till that S must start at first index of line!
Test case 4 is q9$?WWe and expected output is false. Can anyone tell me how is it not matching the given regex pattern?
My java solution:
Though I find the editorial solution to be more elegant