2

Matcher类的构造函数源码:

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();
}

为什么我们不只使用 parent.capturingGroupCount*2 作为组的长度?

4

1 回答 1

1

这可能是为了在没有任何特殊情况的情况下更容易支持反向引用 ( \0- )。\9

于 2013-12-28T15:39:50.650 回答