Next: , Previous: , Up: Functions   [Contents][Index]


4.3 Working with Capturing Groups

The following functions are used to retrieve actual content of a captured group after a successive match. The match is identified by match descriptor returned from a prior call to prce_match or pcre_string_match.

These functions will raise the e_range exception, if the match descriptor is invalid, and the e_inval exception, if the substring number or name refer to a non-existing capturing group.

Function: string pcre_numbered_substring (number mh, number n)

Returns text of the nth captured group of the match mh.

Function: string pcre_named_substring (number mh, string name)

Returns text of the named captured group name in the match mh.

Function: string pcre_expand (number mh, string input)

Given match descriptor mh, replace in input all references to capturing groups with their actual text and return the resulting string.

Numbered capturing groups are referred to as ‘$n’, where n is the group number (0-based, 0 being the portion of the text matching entire regular expression). If n is greater than 9, it should be enclosed in curly braces (e.g. ‘${10}’).

Named capturing groups are referred to as ‘$+{name}’, where name is the group name.