I’m currently on the positive and negative lookahead lesson in the javascript curriculum, and the command is: Use lookaheads in the pwRegex
to match passwords that are greater than 5 characters long, and have two consecutive digits.
Originally, my code was:
let sampleWord = “astronaut”;
let pwRegex = /(?=\w{6,})(?=\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);
but that doesn’t work, and the given solution is:
let sampleWord = “astronaut”;
let pwRegex = /(?=\w{6,})(?=\w*\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);
Why does this work? My second part looks ahead to make sure there are at least two digits right? What difference does the \w* make? I’m having trouble understanding