Tell us what’s happening:
Hi, the answer below works, but I am curious to know why it needs the ‘\w*’ in the second lookahead.
Without the above, the code does not pass. I would think that without it, the code would still lookahead to find 2 digits (\d) and pass the regex, but it fails for the string, bana12, for instance.
Your code so far
let sampleWord = "astronaut";
let pwRegex = /(?=\w{6,})(?=\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/90.0.4430.212 Safari/537.36
Challenge: Positive and Negative Lookahead
Link to the challenge: