Previous Topic: Non-greedy RepeatsNext Topic: Non-Marking Parenthesis


Parenthesis

Parentheses serve two purposes, to group items together into a sub-expression, and to mark what generated the match. For example the expression "(ab)*" would match all of the string "ababab". The matching algorithms regex_match and regex_search each take an instance of match_results that reports what caused the match, on exit from these functions the match_results contains information both on what the whole expression matched and on what each sub-expression matched. In the example above match_results[1] would contain a pair of iterators denoting the final "ab" of the matching string. It is permissible for sub-expressions to match null strings. If a sub-expression takes no part in a match - for example if it is part of an alternative that is not taken - then both of the iterators that are returned for that sub-expression point to the end of the input string, and the matched parameter for that sub-expression is false. Sub-expressions are indexed from left to right starting from 1, sub-expression 0 is the whole expression.