You admitted that you're working with XML. The regex stuff is probably the wrong answer to your problem. You have an XY problem where you're fixated on a solution instead of the problem.
What are you really trying to discover? It's practically impossible to give a good answer to a question such as this if you don't tell us what you are trying to do and why you are trying to do it.
There's a difference between the number of capture groups in the pattern and the number of captures a pattern will produce.
- The total number of literal capture groups in the regex.
This has one capture although there are literally three capture groups. The branch reset grouping renumbers the captures so that each alternation captures into the same variables:
(?|(abc)|(def)|(ghi))
Do you want to count that as three capture groups or just one capture it will produce?
Even without the branch reset, how do you want to count this one?
(abc)|(def)(ghi)|(jkl)
There are four capture groups, but at most only two of them will capture anything.
- The total number of captures that the regex will produce for a particular string.
Besides the previous examples, some capture groups might never capture anything. The number of captures depends on the string you match, as in these examples:
(abc)?
(abc)*
(abc){0,5}
- The maximum number of captures that a regex might produce. That is, for a string that triggers the most number of capture, what is that number?