Re: [問題] boost regex sub-expression
您試用看看吧 vc2008 sp1 tr1裡面的regex 據說是 boost 來的
#include <iostream>
#include <string>
#include <regex>
using namespace std;
using namespace std::tr1;
int main(int argc, char* argv[]) {
string ss("xyz1 xyz2 xyz3 xyz4");
regex rx("((xyz)(\\d))");
/*------------------------------------------------------------*/
cout << "sregex_token_iterator" << endl;
sregex_token_iterator itrBegin2(ss.begin(), ss.end(), rx), itrEnd2;
copy(itrBegin2, itrEnd2, ostream_iterator<string>(cout, "\n"));
cout << endl;
/*------------------------------------------------------------*/
cout << "sregex_iterator" << endl;
sregex_iterator itrBegin(ss.begin(), ss.end(), rx), itrEnd;
for (sregex_iterator itr = itrBegin; itr != itrEnd; ++itr) {
for (unsigned int cou = 0; cou < itr->size(); ++cou) {
cout << itr->str(cou) << ",";
}
cout << endl;
}
system("pause");
return 0;
}/*
sregex_token_iterator
xyz1
xyz2
xyz3
xyz4
sregex_iterator
xyz1,xyz1,xyz,1,
xyz2,xyz2,xyz,2,
xyz3,xyz3,xyz,3,
xyz4,xyz4,xyz,4,
*/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.88.23
推
04/12 20:36, , 1F
04/12 20:36, 1F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):