pcre match all groups in C

前端 未结 2 738
青春惊慌失措
青春惊慌失措 2021-01-16 05:48

I want to match a group recursively using PCRE C library.

e.g.

pattern = \"(\\d,)\"
subject = \"5,6,3,2,\"
OVECCOUNT = 30

pcrePtr = pcre_compile(pat         


        
相关标签:
2条回答
  • 2021-01-16 05:56

    Try this :

    pcre *myregexp;
    const char *error;
    int erroroffset;
    int offsetcount;
    int offsets[(0+1)*3]; // (max_capturing_groups+1)*3
    myregexp = pcre_compile("\\d,", 0, &error, &erroroffset, NULL);
    if (myregexp != NULL) {
        offsetcount = pcre_exec(myregexp, NULL, subject, strlen(subject), 0, 0, offsets, (0+1)*3);
        while (offsetcount > 0) {
            // match offset = offsets[0];
            // match length = offsets[1] - offsets[0];
            if (pcre_get_substring(subject, &offsets, offsetcount, 0, &result) >= 0) {
                // Do something with match we just stored into result
            }
            offsetcount = pcre_exec(myregexp, NULL, subject, strlen(subject), 0, offsets[1], offsets, (0+1)*3);
        } 
    } else {
        // Syntax error in the regular expression at erroroffset
    }
    

    I believe the comments are self explanatory?

    0 讨论(0)
  • Any way I used strtok since "," was repeating after each group..

    Solution using pcre is welcomed....

    0 讨论(0)
提交回复
热议问题