(字边界)我都存储在一个字符串文本文件名为Str
看起来像这样的内容:如何找到一组词的使用正则表达式
Str = "Cat is an animal\n" +
"Cat is small\n" +
"Cat is a pet\n";
我写这个代码搜索的字Cat
:
Pattern pattern = Pattern.compile("(\\bCat\\b)");
Matcher match = pattern.matcher(Str);
while (match.find()) {
String tempStr = "I found " + match.group() + "\n";
}
上面产生这样的输出:
I found Cat
I found Cat
I found Cat
这是我的问题。如何使用关键字Cat查找整个句子,以便输出结果为:
I found Cat is an animal
I found Cat is small
I found Cat is a pet
这是什么正则表达式?
你有什么试过?你没有显示任何找到该句子的企图/线索。我也会说这个问题缺乏细节/背景。 – 2013-02-28 20:19:21
是的,我找到了解决我的问题的方案。我尝试了简单的正则表达式Vlad L建议并返回符合我预期的输出。谢谢! – 2013-02-28 20:58:39