【发布时间】:2011-06-27 18:17:39
【问题描述】:
我是使用 Regex 的新手,我已经浏览了很多教程,但我还没有找到适用于我想做的事情的教程,
我想搜索一些东西,但返回它后面的所有内容,而不是搜索字符串本身
例如“一些很棒的蹩脚句子”
搜索“句子”
return "太棒了"
任何帮助将不胜感激
到目前为止,这是我的正则表达式
sentence(.*)
但它返回:很棒的句子
Pattern pattern = Pattern.compile("sentence(.*)");
Matcher matcher = pattern.matcher("some lame sentence that is awesome");
boolean found = false;
while (matcher.find())
{
System.out.println("I found the text: " + matcher.group().toString());
found = true;
}
if (!found)
{
System.out.println("I didn't find the text");
}
【问题讨论】:
-
您的实际呼叫是什么?你在用
Matcher吗? -
我正在使用匹配器和模式
-
...我们仍然希望查看您的实际 Java 代码以帮助评估问题所在。
-
System.out.println("I found the text: " + "some lame sentance that is aweomse".substring(end())); -
@DavidIsNotHere 纳粹应该有一个大写 N...