/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <string.h>
#include <pcre.h>

void test(char *s)
{
    int ix;
    pcre *re;
    int rc;
    int erroffset;
    int ovector[300];
    const char *error;
    const char *p;
    re = pcre_compile("(?:<body>)(.*?)(?:</body>)",PCRE_CASELESS+PCRE_DOTALL+PCRE_MULTILINE,&error,&erroffset,NULL);
    rc = pcre_exec(re,NULL,s,strlen(s),0,0,ovector,sizeof(ovector)/sizeof(int));
    ix = 0;
    while((rc = pcre_exec(re,NULL,s,strlen(s),ix,0,ovector,sizeof(ovector)/sizeof(int)))>0)
    {
       pcre_get_substring(s,ovector,rc,1,&p);
       printf("%s\n",p);
       ix = ovector[1];
    }
}

int main()
{
    test("<body>1</body>");
    test("<body>1</body><body>2</body>");
    test("<body>1</body><body>2</body><body>3</body>");
    return 0;
}
