Answer the question
In order to leave comments, you need to log in
Regular expressions, why not like this?
You need to find two consecutive numbers in the text, why do you need to write exactly (?=\D*\d{2})? Not just (?=\d{2}).
let sampleWord = "banan1"; (Your regex should not match the string)
let sampleWord = "bana12"; (Your regex should match the string)
let sampleWord = "1a2bcde"; (Your regex should not match the string)
let pwRegex = /(?=\w{6})(?=\w*\d{2})/;
let result = pwRegex.test(sampleWord);
It checks if there are 6 characters in the text, and it must also contain two consecutive digits.
If we enter (?=\D*\d{2}), then it returns true, and if (?=\d{2}), false. I just want to know the mechanics, I can’t find it, as I understand it, what he does, he looks for a pattern of numbers at the beginning, but why?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question