Shortcuts for non-digit characters

Hi guys,
I just realised due to my overthinking brain, that in one of the challenges (link here: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/match-all-non-numbers) is explained, that \D is equivalent to ^[0-9]. That being said, I tried to understand and comprehend in this challenge (link here: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead) that logically this code:
let checkPass = /(?=\w{3,6})(?=\D*\d)/;
should be the same as:
let checkPass = /(?=\w{3,6})(?=^[0-9]*\d)/;
Of course, the problem occured (in vscode), that it isn’t the same and for example the password “abcde1” isn’t working. Can somebody elaborate? :smiley:

The caret ^ in front of the character class [] is a boundary assertion, the ^ has to be inside the character class to invert the match.

1 Like

That’s exactly what I was wondering about. Thanks for the explanation :slight_smile:
Kudos!

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