I’ll keep this succinct:
We just need to edit the second line to match passwords that are greater than 5 characters long, and have two consecutive digits.
The correct line of code is /(?=\w{6,})(?=\w*\d{2})/;
I’m wondering why this doesn’t work: /(?=\w{6,})(?=\d{2})/;
The code in the first set of parentheses satisfies the first rule (must be 5+ characters long) and the code in the second set satisfies the second set (must have two consecutive digits).
The \w*
just means it has 0+ characters before it but that doesn’t mean anything. You could also put that after the \d{2}
but you don’t have to.
I would somewhat understand it if the numbers have to be at the end but they don’t.
Any help would be appreciated.
Your code so far
let sampleWord = "abc456";
let pwRegex = /(?=\w{6,})(?=\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);
console.log(result)
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:90.0) Gecko/20100101 Firefox/90.0
Challenge: Positive and Negative Lookahead
Link to the challenge: