您好,我有下面这段代码,用于查找单词“is”,但不包括它作为其他字符串的一部分的情况,因此单词“this”不应匹配,所以我使用\b。但是下面的代码没有找到匹配项,我无法弄清原因。
public static void main(String[] args) {
String a = "This island is beautiful.";
Pattern p = Pattern.compile("\bis\b");
Matcher m = p.matcher(a);
while(m.find()){
System.out.println(a.substring(m.start(), m.end()));
}
}
m.group()
代替a.substring(m.start(), m.end())
。 - Keppil