什么是正则表达式“独立捕获组”? [英] What is a regex "independent capturing group"?
问题描述
来自Java 6 模式文档:
From the Java 6 Pattern documentation:
特殊构造(非捕获)
Special constructs (non-capturing)
(?:
的 X 的)
   的 X 的,作为非捕获组
(?:
X)
X, as a non-capturing group
...
(?>
X )
X ,作为一个独立的非捕获组 p>
(?>
X)
X, as an independent, non-capturing group
在(?: X)
和之间(?> ; X)
有什么区别? 独立在这种情况下意味着什么?
Between (?:X)
and (?>X)
what is the difference? What does the independent mean in this context?
推荐答案
这意味着分组是 atomic ,它会丢弃匹配组的回溯信息。所以,这种表达是占有欲的;它不会退缩,即使这样做是整个正则表达式成功的唯一途径。它是独立的,因为它不会通过回溯与正则表达式的其他元素合作以确保匹配。
It means that the grouping is atomic, and it throws away backtracking information for a matched group. So, this expression is possessive; it won't back off even if doing so is the only way for the regex as a whole to succeed. It's "independent" in the sense that it doesn't cooperate, via backtracking, with other elements of the regex to ensure a match.
这篇关于什么是正则表达式“独立捕获组”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!