microsoftxiao

记忆 流逝

导航

用Boost来查找过滤字符串

虽然网上讨论不少Boost正则表达式的问题,推荐用其他正则库,但是还是用了下。
[code]
#include <list>
#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>                 //使用正则表达式

#include <iostream>

//#include "../PStringConv/PStringConv.h"

#include <string>
using namespace std;
using namespace boost;

regex expression("[垃圾文字]{8}");   //模式

int main(int argc, char** argv)
{
 cmatch what; 
 string  srcstring = " ";
 while(cin>>srcstring){
  if(srcstring == "exit") break;

  if(regex_search(srcstring.c_str(), what, expression))
  {
   for(int i = 0;i<what.size();i++)
    cout<<"search string:"<<what[i].str()<<endl;
  }
  else
  {
   cout<<"Not have sub string"<<endl;
  }
 }
 return 0;
}
[/code]

posted on 2006-11-10 15:27  龙巢NET刀  阅读(530)  评论(0编辑  收藏  举报