JDK1.6中关于捕获组重复的问题的描述:
The captured input associated with a group is always the subsequence that the group most recently matched.
If a group is evaluated a second time because of quantification then its previously-captured value, if any, will be retained if the second evaluation fails. Matching the string "aba" against the expression (a(b)?)+, for example, leaves group two set to "b". All captured input is discarded at the beginning of each match.
如果因为量词使得一个捕获组在一次匹配中重复计算了,那么只有最后一次匹配上的一次被保存在捕获组中。
所以:aba被(a(b)?)+匹配后,goup(1)==ab, group(2) == b
类似的:<table><tr>abc</tr><tr>def</tr></table>被<table>(?:<tr>(.*?)</tr>)*</table>匹配之后group(1)==def