Regular Expressions: Positive and Negative Lookahead question

This is my code:

let sampleWord = "astronaut";
let pwRegex = /(?=\w{5})(?=\d\d)/; // Change this line
let result = pwRegex.test(sampleWord);

I get errors:

Your regex should match “bana12”

Your regex should match “abc123”

What am I doing wrong?

Actually the example they have given in the tutorial is –

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); // Returns true

but if we give password =“1234”
it returns ‘true’

so i had my confusion while doing this
will try to find out

each lookahead test indipendelntly the string, your second one is matching only numbers, and lookaheads start looking from where the last match was, in this case the beginning of the string.

your two groups will match: (?=\w{5}) only if the string starts with exactly 5 word characters, (?=\d\d) only if the string starts with 2 numbers

@pree : does the thing above explain things for you too?if you give it just numbers, it works because numbers are included in \w

Thanks for the reply.