Positive and Negative Lookahead theory not clear

Positive and Negative Lookahead theory not clear
0

#1

Tell us what’s happening:

in the theoy part

A more practical use of lookaheads is to check two or more patterns in one string. Here is a (naively) simple password checker that looks for between 3 and 6 characters and at least one number:

    let password = "abc123";
    let checkPass = /(?=\w{3,6})(?=\D*\d)/;
    checkPass.test(password); // Returns true

i don’t understand why (?=\D*\d) is used?..because (?=\D*) returns true if there is zero or more non digits.
But we have already checked non digits using (?=\w{3,6}).
if there would have been (?=\d+) then it would have matched one or more digits…which is the requirement by the password checker.

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


#2

\w includes letters, digits, and the underscore character.


#3

what about this (?=\D*\d)