如何使用perl样式内存正则表达式与Boost库匹配

How to use Perl style memory regex matching with Boost library

本文关键字:Boost 正则表达式 何使用 perl 样式 内存      更新时间:2023-10-16

我正在尝试使用Perl的正则记忆功能,该功能将匹配的文本放入()中的变量$ 1,$ 2 ...有人知道我如何通过Boost做到这一点,也许Boost可以将匹配的文本保存在其他位置?以下代码线说$ 1是不确定的。

 boost::regex ex( aaa(b+)aaa, boost::regex::perl );
 if(boost::regex_search( line ,ex ))
   set_value( $1 ); // Here $1 should contain all the b's matched in the parenthesis

谢谢乔

您将需要使用单独的boost::regex_search

过载

特别是您想要一个在boost::match_results结构中传递的地方(通过参考)。只要搜索成功。

boost::match_results<std::string::const_iterator> results;
std::string line = ...; 
boost::regex ex( "aaa(b+)aaa", boost::regex::perl );
 if(boost::regex_search( line ,results, ex ))
   set_value( results[1] );