我想使用命名的子表達式來使用boost :: regex_replace和命名的子表達式來替換輸入字符串中的多個模式。在Boost正則表達式中命名爲Subexpressions錯誤
我使用下面的代碼:
std::string s="Sun Fun Gun Tic Tac Toe ;$!";
boost::regex expr("(?<from1>.un)|(?<from2>[:;!])"); //Throws the error
std::string fmt("(?'from1'nm)(?'from2'sp)");
std::string s2 = boost::regex_replace(s,expr,fmt,boost::match_default|boost::format_all);
std::cout<<s2<<std::endl;
但是,當運行茨艾倫引發以下錯誤:
terminate called after throwing an instance of 'boost::regex_error'
what(): Invalid preceding regular expression
Aborted
請指導,以什麼我可能做錯了什麼?
版本的提升? http://liveworkspace.org/code/5fe67c46a9325236ff224de62c944198 – ForEveR
我正在使用Boost 1.45 – Mindstorm