Java regex capture not working

后端 未结 4 1156
逝去的感伤
逝去的感伤 2020-12-22 11:49

I have a regular expression:

l:([0-9]+)

This should match this string and return three captures (according to Rubular)

\"l:         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-22 12:33

    Matcher.find() returns false when there are no more matches, so you can do a while loop whilst getting and processing each group. For example, if you want to print all matches, you can use the following:

        Matcher m;
        Pattern p = Pattern.compile("l:([0-9]+)");
        m = p.matcher("l:32, l:98, l:1234");
    
        while (m.find()) {
            System.out.println(m.group());
        }
    

提交回复
热议问题