该模式匹配任何floating point
数字,点数前为< = 10位数。
string pattern = (?<value>([1-9][0-9]{0,9})(,[0-9]+){0,1});
string line = " s - ssd";
boost::regex expr{val_pat};
boost::smatch match;
boost::regex_search(line, match, expr);
if(match["value"].matched){
cout << match["value"]<<endl;
}
这段代码给了我
尝试访问unitialized boost :: match_result&lt;&gt;班级错误。
如何安全地提取命名组:值?
答案 0 :(得分:2)
boost::regex_search
的帖子条件为
如果函数返回false,则对参数m的影响未定义,否则对参数m的影响在表中给出:
所以你需要做的是从regex_search
捕获返回以确保它找到了什么,或者可以将它用作if语句的条件,如
if(boost::regex_search(line, match, expr)){
if(match["value"].matched){
cout << match["value"]<<endl;
}
}
如果你可以使用C ++ 11,你可以使用std::regex_search
,即使没有找到匹配项也会更新匹配参数。