小编tbm*_*mvp的帖子

如何使用PCRE获取所有匹配组?

我没有使用C的经验,我需要使用PCRE来获得匹配.
这是我的源代码示例:

int test2()
{
    const char *error;
    int   erroffset;
    pcre *re;
    int   rc;
    int   i;
    int   ovector[OVECCOUNT];

    char *regex = "From:([^@]+)@([^\r]+)";
    char str[]  = "From:regular.expressions@example.com\r\n"\
                  "From:exddd@43434.com\r\n"\
                  "From:7853456@exgem.com\r\n";

    re = pcre_compile (
             regex,       /* the pattern */
             0,                    /* default options */
             &error,               /* for error message */
             &erroffset,           /* for error offset */
             0);                   /* use default character tables */

    if (!re) {
        printf("pcre_compile failed (offset: %d), %s\n", erroffset, error);
        return -1;
    }

    rc = pcre_exec (
        re,                   /* …
Run Code Online (Sandbox Code Playgroud)

c regex pcre pattern-matching

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

c ×1

pattern-matching ×1

pcre ×1

regex ×1