正则表达式-Matcher类中的group方法探析
发布时间:2020-12-14 04:35:58 所属栏目:百科 来源:网络整理
导读:在使用Matcher.group(int group)之前,先应对Pattern中的group的概念有比较清晰的理解。 1.下边来看一下JDK1.7官方文档中关于group概念的解释: strongspan style="font-size:14px;"Groups and capturing/span/strongspan style="font-size:14px;" /spanGrou
在使用Matcher.group(int group)之前,先应对Pattern中的group的概念有比较清晰的理解。
1.下边来看一下JDK1.7官方文档中关于group概念的解释:<strong><span style="font-size:14px;">Groups and capturing</span></strong><span style="font-size:14px;"> </span> Group number Capturing groups are numbered by counting their opening parentheses from left to right. In the expression ((A)(B(C))),for example,there are four such groups: 1 ((A)(B(C))) 2 (A) 3 (B(C)) 4 (C) Group zero always stands for the entire expression. Capturing groups are so named because,during a match,each subsequence of the input sequence that matches such a group is saved.The captured subsequence may be used later in the expression,via a back reference,and may also be retrieved from the matcher oncethe match operation is complete. |