Positive and Negative Lookahead on the \D*

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);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0.

Link to the challenge:

this is what i dont understand here. i get the instructions what to do for the code and this is where they put a wrench of the given solution on the website with \D*. you are asked to write a code with greater than 5 characters and have two digits. why does this need to be called \D* where the instruction specifically asks for digits and characters and not for non characters.

It doesn’t “Need” to be D* I’m pretty sure [0-9]{2} would work. Try your own solutions.

I took off the \D* and replaced with what you sait. still the test cases of bana123 and abc123 dont pass. i dont know why. i am lost

TBH that is not a good example. I’m not sure why they would use that as a solution.


i tested those test cases in the website you provided also. it shows a warning that there are infinite posibilities i dont understand either

Yeah, I’m lost. What they provided is not valid Regex

In a real life scenario I would use (?=[a-z])\w+([0-9]{2}) which is totally valid but it doesn’t use 2 look a heads.
I’m not sure what they are trying to accomplish.

i agree i would \d instead of [0-9] i guess it is the same thing

I don’t have a problem using the metacharacter but like I said their regex isn’t even valid, and doing 2 look aheads…I can’t even think of a use case for that.

You don’t even have look aheads in python anymore. You just make groups and you can use either group by calling it like an array object.