Guardian Native C Library Calls Reference Manual (G06.28+, H06.04+)

regcomp(3) Guardian Native C Library Calls Reference Manual
if (error == REG_NOMATCH) {
printf("No matches in string\n");
return;
} else if (error != 0) {
msize = regerror(error, &preg, message, SLENGTH);
printf("%s\n", message);
if (msize > SLENGTH)
printf("Additional text lost\n");
return;
};
count = 1;
start_search = string + pmatch.rm_eo;
while (error == 0) {
error =
regexec(&preg, start_search, 1, &pmatch,
REG_NOTBOL);
start_search = start_search + pmatch.rm_eo;
count++;
};
count--;
printf("There are %i matches\n", count);
regfree(&preg);
}
2. The following example nds out which subexpressions in the regular expression have
matches in the string. This example uses the same main() program as the preceding
example. This example does not specify REG_EXTENDED in the call to regcomp()
and, consequently, uses basic regular expressions, not extended regular expressions.
#define MAX_MATCH 10
int match(char *pattern, char *string)
{
char message[SLENGTH];
char *start_search;
int error, msize, count, matches_tocheck;
regex_t preg;
regmatch_t pmatch[MAX_MATCH];
error = regcomp(&preg, pattern, REG_ICASE);
if (error) {
msize = regerror(error, &preg, message, SLENGTH);
printf("regcomp: %s\n", message);
if (msize > SLENGTH)
printf("Additional text lost\n");
return;
}
if (preg.re_nsub > MAX_MATCH) {
printf("There are %i subexpressions, checking %i\n",
preg.re_nsub, MAX_MATCH);
matches_tocheck = MAX_MATCH;
} else {
printf(
"There are %i subexpressions in re\n", preg.re_nsub);
564 Hewlett-Packard Company 527192-005