Positive and Negative Lookahead 4246

Tell us what’s happening:

i just cant find where this regex is wrong.

Your code so far


let sampleWord = "astronaut";
let pwRegex = /(?=\w{5,})(?=\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/76.0.3809.132 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead

Hey @Harshlebrown

The first positive lookahead is correct -

The second part is where the problem lies -

Here the lookahead is expecting two or more consecutive digits. We have to also check for Zero or more character apart from number.

So instead of the above positive lookahead
We can write

Regex can be a bit confusing at the beginning. Believe me it will take sometime to understand it.

I used to solve regex problem with regex101.com. It is very helpful for me. Hopefully it will be for you too

1 Like