static int match_regex (_regex_t * r, const char * to_match)
{
// "P" is a pointer into the string which points to the end of the previous match.
const char * p = to_match;
// "N_matches" is the maximum number of matches allowed.
const int n_matches = 10;
// "M" contains the matches found.
_regmatch_t m[n_matches];
while (1) {
int i = 0;
int nomatch = _regexec (r, p, n_matches, m, 0);
if (nomatch) {
printf ("No more matches.\n");
return nomatch;
}
for (i = 0; i < n_matches; i++) {
int start;
int finish;
if (m[i].rm_so == -1) {
break;
}
start = m[i].rm_so + (p - to_match);
finish = m[i].rm_eo + (p - to_match);
if (i == 0) {
printf ("$& is ");
}
else {
printf ("$%d is ", i);
}
printf ("'%.*s' (bytes %d:%d)\n", (finish - start),
to_match + start, start, finish);
}
p += m[0].rm_eo;
}
return 0;
}
Look your code where is the _regexec inside the for loop?
Or you intended it inside the while loop?
The code is not so much readable...