I have a Question about this regex problem

I’m now working on "Positive and Negative Lookahead"Problem,
but I can’t understand why this can’t work well.

my regex is /^(?=\w{4,})(?=\d{2,})$/
and I know this isn’t a correct answer for this problem.
but why this doesn’t match for “bana12” ?
I think this is qualified for at least this one sentence.

best regards

Lookaheads are not matched themself but only checked for the string to match.
And your regex contains two consecutive lookaheads but no actual string to match.
Even if you could combine lookaheads like that (I think you need to put both expression in the same lookahead), they are 6 characters long and so is your word. So there are no characters left in the string to match → because as I said, the lookaheads are not included in the match.


thanks ! I didn’t know how it works but I got it!

the two lookaheads are looking from the same position, the first lookahead matches 4 characters, adding the second lookahead means that the first two characters of those 4 needs to be digits, bana12 isn’t matched because you don’t have 4 consecutive characters of which the first two are digits

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.