目前,我尝试使用Character.isUpperCase
. 但是现在我只想检索句子中每个单词中所有第一个字母都是大写的短语。我应该怎么做。
例如,“这是一个例句,因此 Ang Mo Kio Avenue 1 是 Ang Mo Kio 的一部分。”
我会检索“Ang Mo Kio Avenue 1”和“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]);
}}
真正的意图是提取 3 个或更多大写单词,可选地后跟一个数字