here are my codes:
#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;
}
it seems that the regular expression of \".*?\"(?!')
cause the problem, for i fixed the fault with regular expression of \".*?\"
.Now i have no idea how to use (?!) pattern in c language.How are the segmentation fault and that pattern related.
help me