繁体   English   中英

Boost Regex中的命名子表达式错误

[英]Named Subexpressions error in Boost Regex

我正在尝试使用boost :: regex_replace和命名子表达式来使用命名子表达式替换输入字符串中的多个模式。

我使用以下代码:

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;

但是,当运行thos引发以下错误时:

terminate called after throwing an instance of 'boost::regex_error'
what():  Invalid preceding regular expression
Aborted

请指导我可能做错了什么?

不知道加速,但std::regex (在TR1和C ++ 11),这是基于加速,不支持命名的子表达式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM