HISTORICAL MOTIVATION:
The existence of non-capturing groups can be explained with the use of parenthesis.
Consider the expressions (a|b)c
and a|bc
, due to priority of concatenation over |
, these expressions represent two different languages ({ac, bc}
and {a, bc}
respectively).
However, the parenthesis are also used as a matching group (as explained by the other answers...).
When you want to have parenthesis but not capture the sub-expression you use NON-CAPTURING GROUPS. In the example, (?:a|b)c