正则表达式获取两个单词之间的逗号分隔值

regex get comma seperated values between two words

我有以下查询和 PRCE 正则表达式,我想从中获取 table 个名称。

 FROM   student s, #prefix#.sometable, subject s, marks s   WHERE  ...

(?<=\sfrom)\s+\K(\w*)(?=\s+where)

想要的结果student ssubject smarks s 我不知道如何从第一场比赛中提取。

我正在尝试在 sublime 文本编辑器中查找和替换。

试试这个:\s+(\w*\s)*s

    pcre *myregexp;
    const char *error;
    int erroroffset;
    myregexp = pcre_compile("\s+(\w*\s)*s", PCRE_CASELESS | PCRE_EXTENDED | PCRE_MULTILINE | PCRE_DUPNAMES | PCRE_UTF8, &error, &erroroffset, NULL);
    if (myregexp) {
        int offsets[2*3]; // (max_capturing_groups+1)*3
        int offsetcount = pcre_exec(myregexp, NULL, subject, strlen(subject), 0, 0, offsets, 2*3);
        if (offsetcount > 0) {
            pcre_get_substring(subject, &offsets, offsetcount, 1, &result);
            // group offset = offsets[1*2];
            // group length = offsets[1*2+1] - offsets[1*2];
        } else {
            result = NULL;
        } 
    } else {
        // Syntax error in the regular expression at erroroffset
        result = NULL;
    }

使用@bobblebubble 解决方案,效果达到 90%,我添加了更多条件来匹配我的情况。它可以工作,但它非常激进,会使编辑器挂在大文件或多个文件上。但我可以忍受我所拥有的。她的解决方案:

(?is)(?:\bFROM\b|\G(?!^))(?:[\s,]|#[^\s,]++)*(\b\K(?:\s*(?!WHERE|LEFT\b)\w+){4,})\b(?=.*?\bWHERE\b)