java regex quantifiers

后端 未结 6 2138
春和景丽
春和景丽 2021-01-12 08:00

I have a string like

String string = \"number0 foobar number1 foofoo number2 bar bar bar bar number3 foobar\";

I need a regex to give me th

6条回答
  •  一向
    一向 (楼主)
    2021-01-12 08:21

    Pattern pattern = Pattern.compile("\\w+\\d(\\s\\w+)\1*");
    Matcher matcher = pattern.matcher(string);
    
    while (matcher.find()) {
        System.out.println(matcher.group());
    }
    

提交回复
热议问题