Hi,
Sorry for emailing the developers with this, but I didn't see a
general pcre-users mailing list.
I've got one that's got me scratching my head, though I'm sure I'm
missing something simple.
I'm trying to search the subject "[VOR]" for the expression "\[VOR\]".
It works using pcredemo, but I can't get it to work in my code.
Here it is in pcredemo:
rtp-wwilliam-vpn12:pcre-7.5 wwilliam$ ./pcredemo "\[VOR\]" "[VOR]"
Match succeeded at offset 0
0: [VOR]
But when run from code, all I get is 1 and 2 in the first ovector
element, giving "[".
> pcre *c_regex = NULL;
> const char *errptr;
> int erroffset, errorcodeptr, *ovector = NULL, num_substrings = 0,
> ret = 0, pcre_options = 0, len=0, num_elements = 0;
>
> c_regex = pcre_compile2("\[VOR\]", pcre_options | PCRE_NEWLINE_ANY,
> &errorcodeptr,
> &errptr, &erroffset, NULL);
>
> ret = pcre_fullinfo( c_regex, NULL, PCRE_INFO_CAPTURECOUNT,
> &num_substrings );
>
> //allocate the amount of memory needed to store our vectors
> ( num captured substrings + 1 * 3) -- see pcre documention on
> pcre_exec for details
> num_elements = ( num_substrings + 1 ) * 3;
> ovector = (int *) malloc(sizeof(int) * num_elements);
>
> char subject[] = "[VOR]";
>
> len = strlen(subject);
>
> ret = pcre_exec(c_regex, NULL, subject, len, 0, 0, ovector,
> num_elements);
>
> Running…
> (gdb) p ovector[0]
> $1 = 1
> (gdb) p ovector[1]
> $2 = 2
> (gdb) p ovector[2]
> $3 = 0
> (gdb) p ovector[3]
> $4 = 0
>
What incredibly stupid mistake am I missing?
Thanks,
Wade