考虑下面的代码片段:
String input = "Print this";
System.out.println(input.matches("\\bthis\\b"));
输出
false
这种方法可能有什么问题呢?如果它是错误的,那么找到精确匹配的单词的正确解决方案是什么?
附言:我在这里找到了各种各样的类似问题,但没有一个能提供我正在寻找的解决方案。提前谢谢。
发布于 2015-08-07 13:10:29
System.out.println(input.matches(".*\bthis$"));
也是有效的。在这里,.*匹配空格之前的任何内容,然后匹配到最后的单词。
https://stackoverflow.com/questions/9464261
复制相似问题