0
pwRegex = /^\D(?=.{5})(?=\w*\d{2})/;

pwRegex = /^\D(?=.{5})(?=\d{2})/;

why does the second line not return true for

console.log(pwRegex.test('astro22'));
  • `s` is not a digit, so it doesn't match when the pattern is at `\d{2}`. You probably wanted something like `(?=\D*\d{2})` – CertainPerformance Sep 21 '20 at 16:35
  • @CertainPerformance You beat Wiktor to it. Let me upvote your most recent answer. – Tim Biegeleisen Sep 21 '20 at 16:35
  • The first regex matches a non-digit if it has at least 5 characters following it. From those 5 characters, the first characters can be any number of characters beeing a letter, digit, or underscore, but it must end with 2 digits. The second regex matches a non-digit if iit has at least 5 characters following it. From those 5 characters the first 2 must be a digit, the other 3 are unspecified. The string `"a22stro"` would for example match the second regex. – 3limin4t0r Sep 21 '20 at 16:47

0 Answers0