Regular Expressions - Positive and Negative Lookahead

Why this regex
/(?=\w{3,6})(?=\d+)/ is not valid to have a password checker that looks for between 3 and 6 characters and at least one number ?

why it should be /(?=\w{3,6})(?=\D*\d)/ ?
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead

Welcome to the forum!
If I am not mistaken, this is some challenge step. If you will provide link to it, it will be easier for others to help you.

Lets write down this two parts:

\d+
\D*\d

First, try to translate each of them in English - what do they mean?

\d+ => search for any digit element that occurs once or more

\D*\d => search for any non digit element occurs zero or more followed by any digit element

why should i use \D* before \d … its look like \d its enough … but at the end it is not valid .

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.