Tell us what’s happening:
/(?=\w{5,})(?=\D\D*\d{2})/
My solution reads as follows: lookahead for any character appearing 5 or more times and lookahead again for a pattern of two non digits, one of which appearing zero or more times, with two consecutive digits followed.
(?=\w{6})(?=\w*\d{2})
whereas freecodecamp’s solution reads as follows: lookahead for a pattern that is of 6 character length and lookahead again for any character appearing zero or times, with 2 consecutive digits.
Is freecodecamp’s more general? And do I understand what is going on?
Your code so far
let sampleWord = "12345";
let pwRegex = /(?=\w{5,})(?=\D\D*\d{2})/; // or (?=\w{6})(?=\w*\d{2})
let result = pwRegex.test(sampleWord);
let result2 = sampleWord.match(pwRegex);
console.log(result);
console.log(result2);
Challenge: Positive and Negative Lookahead
Link to the challenge: