Regex fails to capture all groups

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

    From java.util.regex.MatchResult.groupCount:

    Group zero denotes the entire pattern by convention. It is not included in this count.

    So iterate through groupCount() + 1.

提交回复
热议问题