我试图按照这里的例子:boost正则表达式不匹配?
http://www.boost.org/doc/libs/1_31_0/libs/regex/doc/syntax.html
我想匹配这种形式的行:
[ foo77 ]
应该是足够简单,我试过的代码片段是这样的:
boost::regex rx("^\[ (.+) \]");
boost::cmatch what;
if (boost::regex_match(line.c_str(), what, rx)) std::cout << line << std::endl;
但我不符合这些线。我尝试了以下变体表达式:
"^\[[:space:]+(.+)[:space:]+\]$" //matches nothing
"^\[[:space:]+(.+)[:space:]+\]$" //matches other lines but not the ones I want.
我做错了什么?
快速猜测:您可能必须转义'\'。在你的情况:boost :: regex rx(“^ \\\ [(。+)\\\]”); – tgmath