Regex: Positive and Negative Lookahead

Spoiler alert: This contains the answer to the problem on https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead

Hello - I got the first part correct(?=\w{5,})

but couldn’t get the second part - my attempt was (?=\d{2}).

So, I admitted defeat and looked at the solution.

But, I don’t understand the solution: (?=\D*\d{2})

Specifically, what the \D* is doing.

I understand that \D matches all non-numbers and that the * matches characters that occur zero or more times, but I don’t see how this relates to the rest of the expression.

Could any one tell me?

Your lookahead of (?=\d{2}) would fail on “abc12”. (?=\D*\d{2}) means “skip over any number of non-digits then match two digits”.

Ok see what you mean - thanks :slight_smile: