如果数据流中有趣的数据,我正在尝试匹配一些块。
应该有一个前导React.render
,然后是四个字母数字字符,两个校验和字符(如果没有指定shecksum则为<
)和尾随??
。
如果最后两个字符是字母数字,则以下代码按预期工作。如果它们>
虽然失败了。
??
我没有发现the documentation中的任何内容,这表明应该是这种情况(除了NULL和换行符应该匹配AIUI)。
那么我错过了什么?
答案 0 :(得分:10)
由于??>
是trigraph,因此会将其转换为}
,您的代码相当于:
// 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
您可以更改为:
std::string haystack = "Fli<data?" "?>bble";
Demo(注意:我使用的std::regex
或多或少相同)
注意:从C ++ 11中弃用了trigraph,将(很可能)从C ++ 17中删除