That quote says that:
If you have used a quantifier - +, *, ? or {m,n}
, on your capture group, and your group is matched more than once, then only the last match will be associated with the capture group, and all the previous matches will be overridden.
For e.g.: If you match (a)+
against the string - "aaaaaa"
, your capture group 1 will refer to the last a
.
Now consider the case, where you have a nested capture group as in the example shown in your quote:
`(a(b)?)+`
matching this regex with the string - "aba"
, you get the following 2 matches:
"ab"
- Capture Group 1 ="ab"
(due to outer parenthesis), Capture Group 2 ="b"
(due to inner parenthesis)"a"
- Capture Group 1 ="a"
, Capture Group 2 = None. (This is because second capture group(b)?
is optional. So, it successfully matches the lasta
.
So, finally your Capture group 1 will contain "a"
,which overrides earlier captured group "ab"
, and Capture group 2 will contain "b"
, which is not overridden.