public class Homework {
public static void main(String[] args) {
String words[] = { "Abendessen", "Affe", "Affen", "aber", "anders", "Attacke", "arrangieren", "Art", "Asien",
"Bund", "Arten", "Biene", "Abend", "baden", "suchen", "A1rten", "Abend-Essen" };
Pattern pattern = Pattern.compile("[aA][a-z[n]+a-z]*");
for (int i = 0; i < words.length; i++) {
Matcher matcher = pattern.matcher(words[i]);
if (matcher.find()) {
System.out.println("OK: " + words[i]);
}
}
}
}
过滤以 a 或 A 开头并包含 n 的单词。这些单词可能仅由字母组成,并且只有以第二个字母开头的小写字母。这些词应该匹配:Abendessen, Affen, anders, arrangieren, Asien, Arten, Abend
我已经粗心地尝试了上面的这个正则表达式,并且认为那也是错误的。
小怪兽爱吃肉
相关分类