When I use "\s" instead of "[:space:]" I get unknown escape sequence `\s'.
here is the code I use (basically the sample code from the PCRE website):
Code:
pcre *re;
char *pattern;
const char *error;
int erroffset;
int ovector[300];
char *subject = xmli->content;
int subject_length = strlen(subject);
int rc, i;
unsigned char *name_table;
int namecount;
int name_entry_size;
pattern = "|<A class=\'res\'[[:space:]]*href=\'(.*)\'>(.*)</A><BR>.*<SPAN[[:space:]]*class=s>(.*)</SPAN>.*<SPAN[[:space:]]*class=ngrn>(.*)</SPAN>|Uis";
//pattern = "|<A class=\'res\'\s*href=\'(.*)\'>(.*)</A><BR>.*<SPAN\s*class=s>(.*)</SPAN>.*<SPAN\s*class=ngrn>(.*)</SPAN>|Uis";
re = pcre_compile(
pattern, /* the pattern */
0, /* default options */
&error, /* for error message */
&erroffset, /* for error offset */
NULL); /* use default character tables */
/* Compilation failed: print the error message and exit */
if (re == NULL)
{
printf("PCRE compilation failed at offset %d: %s\n", erroffset, error);
return;
}
rc = pcre_exec(
re, /* the compiled pattern */
NULL, /* no extra data - we didn't study the pattern */
subject, /* the subject string */
subject_length, /* the length of the subject */
0, /* start at offset 0 in the subject */
0, /* default options */
ovector, /* output vector for substring information */
300); /* number of elements in the output vector */
if (rc < 0)
{
switch(rc)
{
case PCRE_ERROR_NOMATCH: printf("No match\n"); break;
/*
Handle other special cases if you like
*/
default: printf("Matching error %d\n", rc); break;
}
free(re); /* Release memory used for the compiled pattern */
return;
}
if (rc == 0)
{
rc = 300/3;
printf("ovector only has room for %d captured substrings\n", rc - 1);
}
for (i = 0; i < rc; i++)
{
char *substring_start = subject + ovector[2*i];
int substring_length = ovector[2*i+1] - ovector[2*i];
printf("%2d: %.*s\n", i, substring_length, substring_start);
}