Positive and Negative Lookahead RegExr q34uestion

Tell us what’s happening:

Your code so far

let sampleWord = "astronaut";
let pwRegex = /(?=\w{5,})(?=\D*\d{2})/; // Change this line

let result = pwRegex.test(sampleWord);

So my q34uestion is this, why do we need \D*| before d{2}, why doesn’t d{2} work by itself

1 Like

{n} Matches exactly n occurrences of the preceding expression. N must be a positive integer.

\d Matches a digit character. Equivalent to [0-9] .

\D Matches a non-digit character. Equivalent to [^0-9] .

\D can come after \d{2} but you still need it to match non-digits

also d is different from \d

yeah i get that, part i dont get is when we trying to check the 2 consecutive digits why do we need to check non-digits first. Why is it when we put \D*\d{2} it works but \d{2} doesn’t work by itself

It depends on what are the requirements, can you post the link to the challenge?

It basicly checks a password and says it needs to have 5 or more characters and 2 consecutive numbers.
Cant post links, Its from js/reg expressions/ positive and negative lookahead

Something is wrong with this test. I have tried more than 10 codes and can not pass 8pass99 or astr1on11aut.

1 Like

If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.