Re: [pcre-dev] Is the PCRE_CASELESS option invalid in Lookah…

Página superior
Eliminar este mensaje
Autor: Philip Hazel
Fecha:  
A: Hiroshi OHNO
Cc: pcre-dev
Asunto: Re: [pcre-dev] Is the PCRE_CASELESS option invalid in Lookahead assertions?
On Tue, 26 Aug 2008, Hiroshi OHNO wrote:

> I attach the small program. (I use PCRE in Fedora9)
> The result of this program is different from the regular expression of Perl.
> Is the first result of this program right?


Which release of PCRE? The current release (7.7) behaves just like Perl:

$ pcretest zz
PCRE version 7.7 2008-05-07

/^(?!JP)[a-z]*$/i
    jp
No match
    JP
No match
    cn
 0: cn
    CN   
 0: CN



> int main(int argc, char *argv[])
> {
>         int i;
>         for(i = 1; i < argc; i++) {
>                 const char *errptr;
>                 int erroffset;
>                 pcre *preg = pcre_compile("^(?!JP)[a-z]*$", PCRE_CASELESS, &errptr, &erroffset, NULL);
>                 if(preg == NULL) {
>                         if(errptr) {
>                                 printf("Error:%s\n", errptr);
>                         }
>                         continue;
>                 }

>
>                 pcre_extra extra;
>                 int rc;
>                 if((rc = pcre_exec(preg,&extra, argv[i], strlen(argv[i]), 0, 0, NULL, 0)) >= 0) {


You are calling pcre_exec() with "extra" unset. This could cause
trouble. Try using NULL instead.

>                         printf("match(%d):'%s'\n", rc, argv[i]);
>                 } else {
>                         printf("unmatch(%d):'%s'\n", rc, argv[i]);
>                 }
>                 pcre_free(preg);
>         }

>
>         return 0;
> }



Philip

--
Philip Hazel