It seems like using a single regular expression to differentiate between uppercase and lowercase letters as well as digits is not possible. In the world of regex, counting can be quite challenging.
Therefore, I believe the solution will involve using a regex to identify the specific types of characters present, followed by a separate step to count the uppercase characters:
/[A-Za-z0-9]{8,16}/
To validate that the string contains at least two uppercase letters, two lowercase letters, and two digits, you can use these three regex patterns:
/[A-Z].*[A-Z]/
/[0-9].*[0-9]/
/[a-z].*[a-z]/
If a string matches all four of these regex patterns, it will meet the criteria for your password requirements.
Alternatively, you may find it simpler to create a function that counts characters in a loop instead of relying on regexes.
By the way, if you're looking for different ways to construct a regex, a helpful resource is