I don't know what's wrong with my lookahead

Tell us what’s happening:
Hi guys, could you please tell me what are my errors so I can learn from them? Thanks! I’ll explain my code:

my RegEx: /(?=\w{5,})(^\d)(?=[0-9][0-9])/;

I divided my code in 3 parts because 3 were the conditions to pass the test:

(?=\w{5,}) //to match all alphanumeric characters with at least 5 characters in the password

(^\d) //to do not match passwords that begin with numbers

(?=[0-9][0-9]) //to match only passwords with 2 consecutive digits

Your code so far


let sampleWord = "astronaut";
let pwRegex = /(?=\w{5,})(^\d)(?=[0-9][0-9])/; // 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/84.0.4147.105 Safari/537.36.

Challenge: Positive and Negative Lookahead

Link to the challenge:

This will do the opposite. You might be confusing usage of a caret sign, as it’s indeed means “excluding characters” but only in the range:

/^[^\d]/

Or you might have confused capitalization:

/\D/ /* except digit, same as [^0-9] */
/\d/ /* match digit, same as [0-9] */

This will not work in the combination with the first lookahead. Think of regex as a cursor. Place cursor on any position and look ahead of it. :point_up: this means “two numbers ahead of me” and by the time cursor will reach position when this is true, the first lookahead “at least 5 characters ahead” might be false.