boost regex_search 找出所有 匹配串

http://www.hackfans.com.cn/html/wenzhang/bianchengziliao/20090606/60698_2.html

 

void CTestBoostRegExDlg::OnOK()
{
 CString sRet;

 const char *szReg1 = "\\d+?";
 boost::regex regreg(szReg1);

 const char *szReg = "\\d+";
 boost::regex reg(szReg);
  boost::smatch m, what;
 std::string s=  "Calls123.a456!987";
  int new_counter=0;
 int delete_counter=0;
 std::string::const_iterator it=s.begin();
 std::string::const_iterator end=s.end();
 
CString in = "Calls123.a456!987";
 boost::regex_search(LPCSTR(in),what,regreg,boost::match_extra);

 int test = what.size();


 while (boost::regex_search(it,end,m,reg)) {
  // 是 new 还是 delete?
  m[1].matched ? ++new_counter : ++delete_counter;
 int size  = m.size();
  std::string msg(m[1].first, m[1].second);
  sRet = (m.str()).c_str();
  it=m[0].second;
 }

posted on 2010-04-13 22:37  cy163  阅读(3982)  评论(0编辑  收藏  举报

导航