What is the regex to make sure that a given string contains at least one character from each of the following categories.
I know the patterns for individual sets namely [a-z]
, [A-Z]
, \d
and _|[^\w]
(I got them correct, didn't I?).
But how do I combine them to make sure that the string contains all of these in any order?
This question is related to
regex
Bart Kiers, your regex has a couple issues. The best way to do that is this:
(.*[a-z].*) // For lower cases
(.*[A-Z].*) // For upper cases
(.*\d.*) // For digits
In this way you are searching no matter if at the beginning, at the end or at the middle. In your have I have a lot of troubles with complex passwords.
You can match those three groups separately, and make sure that they all present. Also, [^\w]
seems a bit too broad, but if that's what you want you might want to replace it with \W
.
Source: Stackoverflow.com