me72921
me72921

Reputation: 173

java regular expression digits, letters, uppercase, lowercase

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

Answers (1)

Robin
Robin

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

Related Questions