/* 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)
{
    pcre *re;
    int rc;
    int erroffset;
    int ovector[300];
    const char *error;
    const char *p;
    re = pcre_compile("(?:^<html>\\s<body>\\s)(.*)(?:</body></html>$)",PCRE_CASELESS+PCRE_DOTALL+PCRE_MULTILINE,&error,&erroffset,NULL);
    rc = pcre_exec(re,NULL,s,strlen(s),0,0,ovector,sizeof(ovector)/sizeof(int));
    if(rc < 0)
    {
        printf("%s does NOT contain a html body\n",s);
    }
    else
    {
        pcre_get_substring(s,ovector,rc,1,&p);
        printf("%s does contain a html body and it is %s\n",s,p);
    }
}

int main()
{
    test("<html>\n<body>\ntester\n</body></html>");
    test("tester");
    return 0;
}
