Positive and Negative Lookahead ( password checker question )

Your code so far


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

In the example above I receive the same return statement ( “true” ) for using:
/(?=\w{3,6})(?=\D*\d)/; or /(?=\w{3,6})(?=\D+\d)/;
Is there any major difference between +(Repeats the previous item once or more) and *(Repeats the previous item zero or more times) when checking patterns similar to this one ?

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0.

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

\D+ requires at least one non-number. \D* does not require any non-numbers.

Well, you have just answered your question in your question :slight_smile:

+ (Repeats the previous item once or more)

and

* (Repeats the previous item zero or more times)

This is the major difference.
For string ‘abc123’ pattern \D+\d will match 1 group - ‘abc1’ because we need one or more non-digits and one digit, whilst pattern \D*\d will match 3 groups = ‘abc1’, ‘2’ and ‘3’, because we don’t need actually even one non-digit in front (Repeats the previous item zero or more times), but one digit.