Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使用Perl风格的内存正则表达式与Boost库匹配_C++_Regex_Perl_Boost_Pattern Matching - Fatal编程技术网

C++ 如何使用Perl风格的内存正则表达式与Boost库匹配

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

我试图使用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
谢谢,
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]);

如果这有助于您的研究,则该功能称为“捕获”。非常感谢!这就成功了:)