boost中的正则表达式中的"."是表示任意字符吗?还是除\n字符以外?

mfcdeclare mfcdeclare 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
理论上来讲,"."表示的是除\n以外的任意字符,但是经过我的测试,好象"."也可以匹配\n?
这是为什么呢?我的程序如下:

.......//次要代码省略
int main(int argc, char* argv[])
{
char str1[MAX_PATH] = {0};
::strcpy(str1, ".");

regex expression(str1);

std::string in;
cmatch what;
while(true)
{
cout << "enter test string" << endl;

char szIn[MAX_PATH*2] = {0};

::strcpy(szIn, "\n");
if(regex_match(szIn, what, expression))
{
for(int i=0;i<what.size();i++)
cout<<"str :"<<what[i].str()<<endl;
}
else
{
cout<<"Error Input"<<endl;
}


}
return 0;
}

上面的程序,执行结果竟然是匹配,而不是想象中的输入“error input”,难道"."也可以匹配\n字符吗?
谢谢
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
mfcdeclare
VC/MFC 16,550 成员 421,606 内容