Regular Expressions: Positive and Negative Lookahead Andrej

Why doesnt this code work?

let sampleWord = "astronaut";
let pwRegex = /(?=.{6,})(?=(\D+\d{2,}\D*))/
let result = pwRegex.test(sampleWord);

It says Your regex should not match “8pass99”. But I specified that the Regex should look for a match that starts with 1+ non digits–> (\D+).

Also why in this code


let checkPass = /(?=\w{3,6})(?=\D*\d)/;

Do you need the \D* to check if the password has 1 or more digits. Wouldn’t it be enough to just have \d

Thanks,

Andrej