Hey everyone ,
I know the topic has been quite debated already, but after looking into the forum I don’t get a few things there.
My first attempt was writing:
\
let pwRegex = /^\D(?=\w{6,})(\d{2,})/;
Basically, exclude the first sign as a number, using positive lookahead to have at least 6 signs (so > 5) and then using positive lookahead again to make sure there was at least 2 consecutive number.
This doesn’t pass the test. After checking hints and solution, I change it to
let pwRegex = /^\D(?=\w{6,})(\w*\d{2,})/;
Now it passes, but I don’t get why we need the \w*
there as positive lookahead is supposed to make sure the element in the search pattern is there. So just using \d{2,}
should already be making sure there’re 2 consecutive number in my search pattern.
Actually I don’t even get why (\w*\d{2,})
is working and why it doesn’t have to (\w*\d{2,}\w*)
as nothing says in the instructions that the 2 consecutive digits have to be at the end.
Many many thanks for the help and long life to FCC, such an awesome online resource!
Challenge: Positive and Negative Lookahead
Link to the challenge: