Regex fails to capture all groups

后端 未结 5 1279
北荒
北荒 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:08

    m1.groupCount() returns the number of capturing groups, ie. 1 in your first case so you won't enter in this loop for(int i = 1; i

    It should be for(int i = 1; i<=m1.groupCount(); i++)

提交回复
热议问题