Hi all, I'm new here.
Just having problems using regexec in C
I want to match a simple pattern several times, like "(string)", but I always get only one result.
Here is my code:
Code:
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>
int main() {
regex_t r;
char *str = "trying string one string two";
regmatch_t matches[4];
int c;
regcomp(&r, "(string)", REG_EXTENDED | REG_ICASE);
regexec(&r, str, 4, matches, 0);
for(c=0; c<4; c++)
printf("%d\n", matches[c].rm_so);
regfree(&r);
return 0;
}
the output is this:
Tryed the same expression in ruby, and it returned both elements, so I suppose the pattern expression is OK.
What am I doing wrong?
thanks