【发布时间】:2017-03-21 21:26:54
【问题描述】:
如果数据流中有有趣的数据,我会尝试匹配一些块。
应该有一个前导<,然后是四个字母数字字符、两个校验和字符(如果没有指定校验和,则为??)和一个尾随>。
如果最后两个字符是字母数字,则以下代码按预期工作。如果他们是??,尽管它失败了。
// Set up a pre-populated data buffer as an example
std::string haystack = "Fli<data??>bble";
// Set up the regex
static const boost::regex e("<\\w{4}.{2}>");
std::string::const_iterator start, end;
start = haystack.begin();
end = haystack.end();
boost::match_flag_type flags = boost::match_default;
// Try and find something of interest in the buffer
boost::match_results<std::string::const_iterator> what;
bool succeeded = regex_search(start, end, what, e, flags); // <-- returns false
我在 the documentation 中没有发现任何内容,这表明应该是这种情况(除了 NULL 和换行符之外的所有内容都应该与 AIUI 匹配)。
那么我错过了什么?
【问题讨论】:
-
你用的是什么编译器?我的 (gcc) 给出了一个明确的警告,说“trigraph ??> convert to }”。
-
我正在使用带有 2008 工具链的 Visual Studio 2013。
标签: c++ boost boost-regex trigraphs