Regular Expressions - Positive and Negative Lookahead

Hi,
Could you plz explain how this works:
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);

my problem is in (?=\D*\d)/ part, why we write (?=\D*\d)/ to see if there is at least one number?

Thanks
Sara


**Your code so far**

```js
let sampleWord = "astronaut";
let pwRegex = /change/; // Change this line
let result = pwRegex.test(sampleWord);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Challenge: Regular Expressions - Positive and Negative Lookahead

Link to the challenge:

you don’t have any limit on where the number is, so you write \D*\d so that there can be any number of non numbers before the number

1 Like

Thank you so much,
so basically, \D* allows it to search every character of the string up to the end?