Regex fails to capture all groups

后端 未结 5 1331
北荒
北荒 2021-01-29 01:36

Using java.util.regex (jdk 1.6), the regular expression 201210(\\d{5,5})Test applied to the subject string 20121000002Test only captures <

5条回答
  •  忘了有多久
    2021-01-29 02:05

    Change the line

    for(int i = 1; i

    to

    for(int i = 1; i<=m1.groupCount(); i++){      //NOTE THE = ADDED HERE    
    

    It now works as a charm!

提交回复
热议问题