Reputation: 173
I need a regular expression in Java with the following requirements:
I have tried several expressions that don't work - this is the best so far:
(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).*
Upvotes: 1
Views: 4281
Reputation: 9644
Anchor your regex, and don't use .
which allows anything:
^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]*$
^$
matches beginning and end of string, [a-zA-Z0-9]*
makes sure the characters are only those in the character class.
Upvotes: 3