Lookahead Question

Using a positive lookahead, why do I need the " \w * " in the second lookahead? Can’t I just look for 2 consecutive numbers without the the \w? The code below works I’m just looking for an explanation on that. Thank you :slight_smile:

Your code so far

let sampleWord = "astronaut";
let pwRegex = /^\D(?=\w{5,})(?=\w*\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Positive and Negative Lookahead

Link to the challenge:

lookaheads start looking at the same position, if the second lookahead is just matching numbers your string will have to have numbers just at the beginning to pass

1 Like

That makes sense, thank you!