regexec matches parenthetical subexpressions of pattern, it records which parts of string they match. It returns that information by storing the offsets into an array whose elements are structures of type
regmatch_t. The first element of the array (index
0) records the part of the string that matched the entire regular expression. Each other element of the array records the beginning and end of the part that matched a single parenthetical subexpression.
It then goes on to say this:
When you call
regexec, you specify how long the matchptr array is, with the nmatch argument. This tells
regexec how many elements to store. If the actual regular expression has more than nmatch subexpressions, then you won’t get offset information about the rest of them. But this doesn’t alter whether the pattern matches a particular string or not.
So does this mean that nmatch should contain the number of subexpressions and the array should be one bigger (as element 0 matches the whole string) or that nmatch should be equal to the size of the array?
- Java regex to match XML processing instructions (acolleoni.wordpress.com)
- Regex Toolkit, Prayer-Based Parsing, Bad Examples (chrisjwarwick.wordpress.com)
- Regex syntax and semantics varies (staffannoteberg.com)