C ++中出现意外的正则表达式结果

时间:2013-04-26 03:16:49

标签: c++ regex c++11

我正在尝试使用正则表达式匹配输入文件中的行,我已经开始使用此测试用例来匹配我想要的行类型。

#include <iostream>
#include <regex>


int main(int argc, char *argv[]) {
    std::string s("%%%% Data and file %%%%");
    std::regex expr("%%%% (.*) %%%%", std::regex_constants::basic);
    bool match = regex_match(s, expr);
    std::cout<<match;
}

我希望提供的正则表达式与搜索字符串匹配,因为我在两个独立的正则表达式测试器上测试了这个表达式。为什么C ++不匹配?此外,我也尝试了其他表达式,它们应该匹配搜索字符串,但它们都不起作用。我开始认为我忽略了C ++正则表达式实现中的一些微妙之处。

0 个答案:

没有答案