Finding all of the matching substrings, not only the “most extended” one

后端 未结 5 1873
甜味超标
甜味超标 2020-12-06 06:02

The code

String s = \"y z a a a b c c z\";
Pattern p = Pattern.compile(\"(a )+(b )+(c *)c\");
Matcher m = p.matcher(s);
while (m.find()) {
    System.out.pri         


        
5条回答
  •  太阳男子
    2020-12-06 06:20

    The only way I can think of here would be to generate a list of all possible substrings of your original string and match the regex against each of them, retaining those items where it matched.

提交回复
热议问题