我是新手使用Regex,我一直在经历一些教程,但我没有找到一个适用于我想做的事情,
我想搜索一些东西,但返回它后面的所有内容,但不返回搜索字符串本身
例如" 一些蹩脚的句子很棒 "
搜索" 句子 "
回归" 太棒了 "
任何帮助将非常感激
到目前为止这是我的正则表达式
sentence(.*)
Run Code Online (Sandbox Code Playgroud)
但它返回:句子太棒了
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");
}
Run Code Online (Sandbox Code Playgroud)