虽然网上讨论不少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]