Getting the text that follows after the regex match

后端 未结 5 1740
你的背包
你的背包 2020-11-22 11:33

I\'m new to using Regex, I\'ve been going through a rake of tutorials but I haven\'t found one that applies to what I want to do,

I want to search for something, but

5条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 12:13

    if Matcher is initialized with str, after the match, you can get the part after the match with

    str.substring(matcher.end())
    

    Sample Code:

    final String str = "Some lame sentence that is awesome";
    final Matcher matcher = Pattern.compile("sentence").matcher(str);
    if(matcher.find()){
        System.out.println(str.substring(matcher.end()).trim());
    }
    

    Output:

    that is awesome

提交回复
热议问题