From the Java 6 Pattern documentation:
Special constructs (non-capturing)
(?:
X)
X, as a non-capturing group
…
(?>
X)
X, as an independent, non-capturing group
Between (?:X)
and (?>X)
what is the difference? What does the independent mean in this context?
Answer
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.
No comments:
Post a Comment