Saturday, 10 September 2016

java - What is a regex "independent capturing group"?



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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...