What is the simplest regular expression that will check if a string contains at least one uppercase letter and one lowercase?
Edit: This is for a password where there may be numeric characters present as well, so the uppercase and lowercase chars might not be next to each other.
I suspect you mean “ASCII character”.
[A-Z].*[a-z]|[a-z].*[A-Z]^(?=.*?[A-Z])(?=.*?[a-z])The “simple” variant just checks for the two possibilities: Either the uppercase character comes before the lowercase, or it’s the other way around.
The “elegant” variant uses two positive look-ahead assertions to scan the string without actually moving the regex engine forward or matching anything.
In contrast to the first method, this variant is very easily extendable for more checks and it allows you to consume the string after you checked that it meets your requirements.