作者:万秀寺求_964 | 来源:互联网 | 2023-06-04 16:39
在linux平台下,使用1c++11正则表达式错误。。1234567891011121314151617181920212223242526272829303132333435363738394041
在linux平台下,使用
正则表达式错误。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| bool isPattern(string str,string pattern)
{
bool tag=false;
if(str.size() > 0 && pattern.size() >0)
{
string match;
regex_t reg;
char errbuf[1024];
char *buff=new char[str.size()];
int err=0;
int nm=1024;
memcpy(buff,str.c_str(),str.size());
regmatch_t pmatch[nm];
if(regcomp(®,pattern.c_str(),REG_NEWLINE|REG_EXTENDED) <0){
regerror(err,®,errbuf,sizeof(errbuf));
cout< }
err=regexec(®,buff,nm,pmatch,0);
if(err==REG_NOMATCH) {
cout<<"no match"< }
else if(err)
{
regerror(err,®,errbuf,sizeof(errbuf));
cout<
}
else
{
int len=0;
for(int i=0;i {
len=pmatch[i].rm_eo-pmatch[i].rm_so;
if(len > 0)
{
match.clear();
match.assign(buff+pmatch[i].rm_so,len);
cout<<"匹配结果:"< tag=true;
// match.clear();
}
}
regfree(®);
}
delete [] buff;
}
return tag;
} |
原始字符串
string str="huangyong"urlname:" "三明治"h good way "urlname:" "蔬菜"h hello world "urlname:"h "apple", wiofjofiewajoi";
正则表达式
string pattern=""urlname:".*?"";
程序运行结束后,输出的结果是:匹配结果:"urlname:" "三明治"h good way "urlname:" "蔬菜"h hello world "urlname:"h "apple"
这个正则表达式通过在线测试工具是正确的,但是输出的结果却不是想要的。
各位大神,求助啊。。