Lookaheads Exercise - Help!

Tell us what’s happening:

Okay, so all the tests have been passed except for the one that says there needs to be two lookaheads. But haven’t I already used two lookaheads? I’m confused. :neutral_face:

Your code so far


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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15.

Challenge: Positive and Negative Lookahead

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

the tests are looking for pattern (?=...)(?=...) where the dots mean any character of any length
Also, a quantifier following a lookaround serves no purpose, and can safely be removed from the regular expression

you could find that unnesting the lookarounds you will not pass some tests

1 Like

That’s odd. But thanks!