I think the answer for the “Regular Expressions: Positive and Negative Lookahead” is wrong (even though it passes all the tests). The is because the question states that it cannot begin with a number. I think for this reason the * sign should be a + sign, and perhaps another test should be added e.g. “123456”
Blockquote
let sampleWord = “astronaut”;
let pwRegex = /(?=\w{6,})(?=\D*\d{2})/;
let result = pwRegex.test(sampleWord);
Thanks for looking into this guys, and good catch with the ^ symbol. However, I still don’t think this catches the test - which doesn’t exist, but should - of: ‘123456’).
I just ran it and still comes through as ‘true’. Even though it starts with a number (question states that it can’t start with a number).
Perhaps there should be a new test for “123456” that the regex should not match? I’d be interested to hear your thoughts:
Use lookaheads in the pwRegex to match passwords that are greater than 5 characters long, do not begin with numbers, and have two consecutive digits.
It will probably help to explicitly state in the error message that ONLY two positive lookaheads can be used (and nothing outside of that).
As far as I can tell this solution works in all cases, except in the FCC test env: /(?=\w{5,})^\D+\w*(?=\d{2,})\w*/i