1

使用 pcre_compile 和 pcre_exec 时如何忽略大小写?

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

我使用什么选项,我在哪里指定它?

4

2 回答 2

4

您需要将PCRE_CASELESS第二个参数传递给pcre_compile,如下所示:

pcre_compile(pattern, PCRE_CASELESS, ...

(请注意,您正在那里泄漏内存 - 您需要调用pcre_free. 返回的对象pcre_compile。)

于 2009-10-27T18:01:19.577 回答
3

您可以PCRE_CASELESS在 pcre_compile 中使用该标志。

例子:

  pcre_compile(
    pattern,              /* the pattern */
    PCRE_CASELESS|PCRE_MULTILINE,                    /* default options */
    &error,               /* for error message */
    &erroffset,           /* for error offset */
    NULL);                /* use default character tables */
于 2009-10-27T18:02:22.207 回答