matcher.find()底层源码分析:
* 1. 根据指定的规则 ,定位满足规则的子字符串(比如(19)(98))
* 2. 找到后,将 子字符串的开始的索引记录到 matcher 对象的属性 int[] groups;
* 2.1 groups[0] = 0 , 把该子字符串的结束的索引+1 的值记录到 groups[1] = 4
* 2.2 记录 1 组()匹配到的字符串 groups[2] = 0 groups[3] = 2
* 2.3 记录 2 组()匹配到的字符串 groups[4] = 2 groups[5] = 4
* 2.4.如果有更多的分组.....
* 3. 同时记录 oldLast 的值为 子字符串的结束的 索引+1 的值 如 10, 即下次执行 find 时,就从 10 开始匹配
* matcher.group(0) * 源码分析 :
* public String group(int group) {
* if (first < 0)
* throw new IllegalStateException("No match found");
* if (group < 0 || group > groupCount())
* throw new IndexOutOfBoundsException("No group " + group);
* if ((groups[group*2] == -1) || (groups[group*2+1] == -1))
* return null;
* return getSubSequence(groups[group * 2], groups[group * 2 + 1]).toString();
* }
* 1. 根据 groups[0] = 0 (在整个字符串中找到的起始位置) 和 groups[1] = 5 (在整个字符串中找到的末位置) ,从 整个字符串截取子字符串返回
* 就是 [0,5) 包含 0 但是不包含索引为 5 的位置
* 如果再次指向 find 方法.仍然按上面分析来执行
转义符