I'm trying to use patterns.c for some pattern matching. The manual mentions captures using "()" around what you want to capture. I don't see how to get at the data though. Here is a sample program.

#include <stdio.h>
#include "patterns.h"

int
main(int argc, char *argv[])
{
    const char        *errstr = NULL;
    const char        *string = "the quick the brown the fox";
    const char        *pattern = "the";
    int            ret;
    struct str_match     match;

    ret = str_match(string, pattern, &match, &errstr);

    if (errstr != NULL)
        printf("%s\n", errstr);
    else
        printf("number of matches %d\n", match.sm_nmatch);

    return 0;
}

It prints 2 which I was expecting 3. I've tried multiple other patterns and it seems the answer is always 2. Which leads me to believe I'm doing something wrong. Any assistance appreciated.


Thanks,


Edgar

Reply via email to