I can’t understand why the answer to this challenge fulfills the requierments.
requirements:
Use lookaheads in the pwRegex
to match passwords that are greater than 5 characters long, do not begin with numbers, and have two consecutive digits.
- greater than 5 characters, digits or numbers, therefore six or more >
(?=\w{6,})
- doesn’t begin with a number could be written multiple ways right?
could a negative lookbehind be used here?(?<!\d)
or^[^\d]
or (i found later)^\D
- has two consecutive numbers.
this part is not location specific in the string >(?=\d\d)
let sampleWord = "astronaut";
let pwRegex = /^\D(?=\w{6,})(?=\d\d)/i;
let result = pwRegex.test(sampleWord);
Why doesn’t this work?
more specifically
why is the answer to strictly only allow 5 chars? why does the double digit portion not work? and why would the negative lookbehind not work as well?
There’s something about regex I’m just not grasping here.
I’m completely confounded by this challenge lol! I would appreciate any clarifications
Thank you!