Method 01:
Code:
let sampleWord = "astronaut";
let pwRegex = /(?=^\D)(?=\w{5,})(?=\w*\d{2,}\w*)/; // Change this line
let result = pwRegex.test(sampleWord);
Output:
Passed
Method 02:
Code:
let sampleWord = "astronaut";
let pwRegex = /(?!^\d)(?=\w{5,})(?=\w*\d{2,}\w*)/; // Change this line
let result = pwRegex.test(sampleWord);
Output:
// running tests
Your regex should not match "8pass99"
But why method 02 is not working? What is the difference
between (?!^\d)
and (?=^\D)
?