Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex: how to know that string contains at least 2 upper case letters?

Tags:

java

regex

How to know that string contains at least 2 upper case letters? For example these are valid strings "Lazy Cat", "NOt very lazy cat". Working with Java 1.7.

like image 991
Ernestas Gruodis Avatar asked Sep 10 '13 08:09

Ernestas Gruodis


2 Answers

Try with following regex:

"^(.*?[A-Z]){2,}.*$"

or

"^(.*?[A-Z]){2,}"
like image 178
hsz Avatar answered Sep 22 '22 10:09

hsz


This regex works.

string.matches(".*[A-Z].*[A-Z].*")
like image 20
Jules G.M. Avatar answered Sep 20 '22 10:09

Jules G.M.