获取正则表达式匹配后的文本
我是使用正则表达式的新手,我一直在学习一系列教程,但我还没有找到一个适用于我想做的事情,
我想搜索某些内容,但返回其后面的所有内容,但不返回搜索字符串本身
例如,“一些蹩脚的句子真棒"
搜索“句子”"
返回“真棒"
任何帮助将不胜感激
到目前为止,这是我的正则表达式
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");
}