Words with at least 2 Capital letters and with any special letters (like @#$%^&*()_-+= and so on...) optional.
I tried:
public static boolean isWordHas2Caps(String s) {
return s.matches("\\b(?:\\p{Ll}*\\p{Lu}){2,}\\p{Ll}*\\b");
}
But, I am getting
System.out.println(isWordHas2Caps("eHJHJK"));
System.out.println(isWordHas2Caps("YUIYUI"));
System.out.println(isWordHas2Caps("LkfjkdJkdfj"));
System.out.println(isWordHas2Caps("LLdkjkd"));
System.out.println(isWordHas2Caps("OhdfjhdsjO"));
System.out.println(isWordHas2Caps("LLLuoiu9898"));
System.out.println(isWordHas2Caps("Ohdf&jh/dsjO"));
System.out.println(isWordHas2Caps("auuuu"));
System.out.println(isWordHas2Caps("JJJJJJJJ"));
System.out.println(isWordHas2Caps("YYYY99999"));
System.out.println(isWordHas2Caps("ooooPPPP"));
Output:
true eHJHJK
true YUIYUI
true LkfjkdJkdfj
true LLdkjkd
true OhdfjhdsjO
false LLLuoiu9898 It should be true but getting false
false Ohdf&jh/dsjO It should be true but getting false
false auuuu
true JJJJJJJJ
false YYYY99999 It should be true but getting false
true ooooPPPP
I think, I should in the regexp and numbers and Special letters. How can I do that?