//CListboost::smatch,boost::smatch& Q_Regex::QRegexList(std::string htmlcode,CString RegStr)
//{ //提取子串
// boost::smatch mat;
// boost::regex reg(RegStr);
// bool r=boost::regex_match(htmlcode, mat, reg);
// CListboost::match_results<std::string::const_iterator,boost::match_resultsstd::string::const_iterator&> clist;
// if(r) //如果匹配成功
// {
// //显示所有子串
//
// for (int i = 0; i < mat.size(); i ++)
// clist.AddTail(mat[i]);
// }
//
//
// return clist;
//
//}
clist.AddTail(mat[i]);这里提示类型不对,不知道mat怎么转sub_match,或者用其他什么方法
用sregex_token_iterator
#include <boost/regex.hpp>
#include <string>
#include <iostream>
using namespace std;
using namespace boost;
int main()
{
string input = "test1 ,, test2,, test3,, test0,,";
boost::regex r("(test[0-9])(?:$|[ ,]+)");
boost::smatch what;
std::string::const_iterator start = input.begin();
std::string::const_iterator end = input.end();
while (boost::regex_search(start, end, what, r))
{
string stest(what[1].first, what[1].second);
cout << stest << endl;
// Update the beginning of the range to the character
// following the whole match
start = what[0].second;
}
// Alternate method using token iterator
const int subs[] = {1}; // we just want to see group 1
boost::sregex_token_iterator i(input.begin(), input.end(), r, subs);
boost::sregex_token_iterator j;
while(i != j)
{
cout << *i++ << endl;
}
return 0;
}