The source code of constructor of Matcher class:
Matcher(Pattern parent, CharSequence text) {
this.parentPattern = parent;
this.text = text;
// Allocate state storage
int parentGroupCount = Math.max(parent.capturingGroupCount, 10);
groups = new int[parentGroupCount * 2];
locals = new int[parent.localCount];
// Put fields into initial states
reset();
}
Why we don't just use parent.capturingGroupCount*2 as the length of groups?
It's probably to make it easier to support backreferences (
\0
-\9
) without having any special cases.