2009-10-27 34 views
1

如何在使用pcre_compile和pcre_exec時忽略大小寫?忽略libpcre中的case與c

pcre_exec(
    pcre_compile(pattern,0,&error,&erroroffset,0), 
    0, string, strlen(string), 0, 0, ovector, sizeof(ovector)); 

我該使用什麼樣的選項,我在哪裏指定它?

回答

4

您需要在第二個參數傳遞給PCRE_CASELESSpcre_compile,像這樣:

pcre_compile(pattern, PCRE_CASELESS, ... 

(請注意,你泄漏內存那裏 - 你需要調用由pcre_compile返回的對象上pcre_free

3

您可以使用pcre_compile中的PCRE_CASELESS標誌。

實施例:

pcre_compile(
    pattern,    /* the pattern */ 
    PCRE_CASELESS|PCRE_MULTILINE,     /* default options */ 
    &error,    /* for error message */ 
    &erroffset,   /* for error offset */ 
    NULL);    /* use default character tables */