[pcre-dev] Is the PCRE_CASELESS option invalid in Lookahead …

Top Page
Delete this message
Author: Hiroshi OHNO
Date:  
To: pcre-dev
Subject: [pcre-dev] Is the PCRE_CASELESS option invalid in Lookahead assertions?
I have a question about PCRE_CASELESS.

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?

$ ./sample jp JP cn CN
match(0):'jp'        <-- Is this result right?
unmatch(-1):'JP'
match(0):'cn'
match(0):'CN'


$ ./sample.pl
unmatch
unmatch
match
match

----- sample.c
#include <stdio.h>
#include <pcre.h>
#include <string.h>

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) {
                        printf("match(%d):'%s'\n", rc, argv[i]);
                } else {
                        printf("unmatch(%d):'%s'\n", rc, argv[i]);
                }
                pcre_free(preg);
        }


        return 0;
}


----- sample.pl
#!/usr/bin/perl

$test1 = 'JP';
$test2 = 'jp';
$test3 = 'CN';
$test4 = 'cn';

if($test1 =~ /^(?!JP)[A-Z]*$/i) {
        print "match\n";
} else {
        print "unmatch\n";
}


if($test2 =~ /^(?!JP)[A-Z]*$/i) {
        print "match\n";
} else {
        print "unmatch\n";
}


if($test3 =~ /^(?!JP)[A-Z]*$/i) {
        print "match\n";
} else {
        print "unmatch\n";
}


if($test4 =~ /^(?!JP)[A-Z]*$/i) {
        print "match\n";
} else {
        print "unmatch\n";
}


----------
Hiroshi OHNO
Mail: hiroshi@???