Currently i have tried getting words that start with an upper case in a sentence using Character.isUpperCase
. However now i would like to only retrieve phrases in a sentence where all the 1st letter in every word of the phrase is upper case. How should i go about doing it.
E.g "This is a sample sentence so that Ang Mo Kio Avenue 1 is part of Ang Mo Kio."
I would retrieve "Ang Mo Kio Avenue 1" and "Ang Mo Kio".
String s = "This is a sample sentence so that Ang Mo Kio Avenue 1 is part of Ang Mo Kio.";
String[] words = s.split("[^a-zA-Z']+");
for (int i = 0; i < words.length; i++) {
if (Character.isUpperCase(words[i].charAt(0))) {
System.out.println(words[i]);
}}
The real intention is to extract 3 or more uppercase words, optionally followed by a number