C++ 如何使用Perl风格的内存正则表达式与Boost库匹配
我试图使用Perl的正则表达式内存特性,它将匹配的文本放入变量$1、$2的()中。。。 有人知道我如何使用Boost实现这一点吗?也许Boost会将匹配的文本保存到其他位置? 下面的代码行表示$1未定义C++ 如何使用Perl风格的内存正则表达式与Boost库匹配,c++,regex,perl,boost,pattern-matching,C++,Regex,Perl,Boost,Pattern Matching,我试图使用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 m
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
谢谢,
Joe您需要使用一个单独的重载
boost::regex\u 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] );
boost::匹配结果;
字符串行=。。。;
boost::regex(“aaa(b+)aaa”,boost::regex::perl);
if(boost::regex_搜索(行、结果、ex))
设置_值(结果[1]);
如果这有助于您的研究,则该功能称为“捕获”。非常感谢!这就成功了:)