Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
执行函数时出现分段错误;regexec";\";的正则表达式是什么\&引用;(?!&x27;)_C_Regex - Fatal编程技术网

执行函数时出现分段错误;regexec";\";的正则表达式是什么\&引用;(?!&x27;)

执行函数时出现分段错误;regexec";\";的正则表达式是什么\&引用;(?!&x27;),c,regex,C,Regex,这是我的密码: #include <regex.h> #include <string.h> char solveRegExpress(const char *pcCommand,const char* pPattern,regmatch_t* pMatch) { int uFlags = REG_EXTENDED | REG_ICASE; int uStatus =

这是我的密码:

#include <regex.h>
#include <string.h>

char solveRegExpress(const char *pcCommand,const char* pPattern,regmatch_t* pMatch)
{
    int uFlags              =             REG_EXTENDED | REG_ICASE;
    int uStatus             =             0;
    const size_t Nmatch     =             1;
    regex_t tRegExpress;
    regmatch_t Tmatch[20];


    regcomp(&tRegExpress ,pPattern,(int)uFlags);
    uStatus   =   regexec(&tRegExpress,pcCommand,Nmatch,Tmatch,0);
    if(0 == uStatus)
    {
        if(tRegExpress.re_nsub>1)
        {
            if(pMatch!=nullptr)
            {
                pMatch->rm_so = Tmatch->rm_so;
                pMatch->rm_eo = Tmatch->rm_eo;
            }
            regfree(&tRegExpress);
            return 3;
        }
        if(pMatch!=nullptr)
        {
            pMatch->rm_so = Tmatch->rm_so;
            pMatch->rm_eo = Tmatch->rm_eo;
        }
        regfree(&tRegExpress);
        return 0;
    }
    else
    {
        regfree(&tRegExpress);
        return 1;
    }
}

char checkForStrSign(char* pcStr,int* endPos)
{
    regmatch_t sGmatch ;
    memset(&sGmatch,0,sizeof (sGmatch));
    if( 1 == solveRegExpress(pcStr,"\".*?\"(?!')",&sGmatch))
    {
        return 1;
    }
    *endPos  =  (int)sGmatch.rm_eo;
    return  0;
}


int main(int argc, char *argv[])
{
    int pos;
    checkForStrSign("str1<<\"str2\"<<str3",&pos);

    return 0;
}
#包括
#包括
char solveRegExpress(常量char*pcCommand,常量char*pPattern,regmatch\u t*pMatch)
{
int uFlags=REG|u EXTENDED | REG|u ICASE;
int uStatus=0;
常数大小匹配=1;
regex_t tRegExpress;
regmatch_t Tmatch[20];
regcomp(和tRegExpress、pPattern(内部)uFlags);
uStatus=regexec(&tRegExpress,pcCommand,Nmatch,Tmatch,0);
如果(0==uStatus)
{
如果(tRegExpress.re_nsub>1)
{
如果(pMatch!=nullptr)
{
pMatch->rm_so=Tmatch->rm_so;
pMatch->rm_eo=Tmatch->rm_eo;
}
regfree(&tRegExpress);
返回3;
}
如果(pMatch!=nullptr)
{
pMatch->rm_so=Tmatch->rm_so;
pMatch->rm_eo=Tmatch->rm_eo;
}
regfree(&tRegExpress);
返回0;
}
其他的
{
regfree(&tRegExpress);
返回1;
}
}
字符checkForStrSign(字符*pcStr,整数*endPos)
{
regmatch_sGmatch;
memset(&sGmatch,0,sizeof(sGmatch));
if(1==solveRegExpress(pcStr,“\”*?\“(?!”)”,&sGmatch))
{
返回1;
}
*endPos=(int)sGmatch.rm_eo;
返回0;
}
int main(int argc,char*argv[])
{
int pos;

checkForStrSign(“str1您需要从
regcomp
检查返回代码。切勿假设标准库函数返回成功,尤其是在您以前没有使用过该函数的情况下


Posix正则表达式不实现非贪婪重复或前瞻断言。因此,
regcomp
可能在抱怨
(?
。请尝试
man 7 regex
以获取受支持的regex组件的完整列表。另请参阅
regerror
函数(在
man 3 regex
中有说明)用于将错误状态转换为(某种程度上)有意义的消息。

如何调用
checkForStrSign
?问题可能就在那里。它在哪里崩溃?调试器告诉了你什么?问题可能在你意想不到的地方。请提供一个。对不起,我的错。现在我已更改了示例。请尝试以下操作:
(\?!\)
或尝试使用gdb或任何其他调试器,并尝试找出错误发生的确切位置
(\?!\)
不起作用。这是一个有用的建议。非常感谢。