What Characters Matched

Figure 21-2.
When an expect function returns, the variable exp_buffer points to the buffer of characters that were being considered for a match. exp_buffer_end points to one character past the end of the buffer. The buffer is null-terminated. If a pattern matches, the variable exp_match is set to point into the same buffer but at the position where the pattern first matches. The variable exp_match_end points to one past the last matching character. All of these variables are character pointers.
char *exp_buffer; char *exp_buffer_end; char *exp_match; char *exp_match_end;
Parenthesized subpatterns from regular expressions have their match information saved but only if the compiled form is used. Each regexp object includes the following members:
#define NSUBEXP 10 char *startp[NSUBEXP]; char *endp[NSUBEXP];
Each subpattern match is defined by a startp and endp pair. startp points to the start of the matching string, and endp points to one past the end of the matching string. startp[0] and endp[0] are identical to exp_match and exp_match_end. The remaining indices correspond to the parenthesized subpatterns in the original pattern. startp is set to 0 if the subpattern did not match.
For example, here is a fragment to print out all of the match information. In the loop, the submatch is temporarily null-terminated so that it can be printed. (The endp pointers are always ...