As I said in a comment, regex is almost certainly not suitable for this job. It will be much easier to write code that iterates over password characters by counting the number of characters in each class.
You have not defined what a "special character" is. I guess this means any character other than a letter or number (including spaces and control characters). I also suggest that the “letters” refer to only 26 letters of the English alphabet, which means that a non-English letter like ñ is a special character.
To take a simpler example, regular expressions don't really express things like "foo and bar in any order"; you must explicitly specify both orders:
foo.*bar|bar.*foo
In this case, you need 12 different options. I think this is correct, but I have not tested it.
[az].*[AZ}|[AZ].*[az}|[az].*[0-9]|[0-9].*[az]|[az].*[^a-zA-Z0-9]|[^a-zA-Z0-9].*[az]|[AZ].*[0-9]|[0-9].*[AZ]|[AZ].*[^a-zA-Z0-9]|[^a-zA-Z0-9].*[AZ]|[0-9].*[^a-zA-Z0-9]|[^a-zA-Z0-9].*[0-9]
This is a regular expression such as egrep or Perl. grep does not recognize | default; if you need a grep line regular expression, replace each | on \| .
And if changing requirements, say, require at least 3 out of 5 character classes, you need to completely rewrite the regular expression; you cannot just configure it.
Please note that your requirements still allow Aa .
source share