c++ boost正则使用

#include #include #include using namespace std; using namespace boost; /*搜索字符串中是否含有子字符串 int main( int argc, char* argv[] ) { char *buf = "This is boost::regex example boost::regex"; boost::regex exampleregex( "boost::regex" ); boost::cmatch result; if( boost::regex_search( buf, result, exampleregex ) ) { std::cout << result.str() << std::endl; } //boost::regex_replace(buf,) return 0; }*/ //写了个去除左侧无效字符(空格,回车,TAB)的正则表达式。 /*void main() { std::string testString = " \r\n Hello World ! GoodBye World\r\n"; std::string TrimLeft = "([\\s\\r\\n\\t]*)(\\w*.*)"; boost::regex expression(TrimLeft); testString = boost::regex_replace( testString, expression, "$2" ); std::cout<< "TrimLeft:" << testString <)(.+?)(?=))"; //regstr = "((?=.+))"; boost::regex expression(regstr); std::string testString = "sdaaccfsaaccdf192dfsdbbdd.168sdfs.sdfs4dsf.sfdsd1asfscvasdf"; boost::smatch what; std::string::const_iterator start = testString.begin(); std::string::const_iterator end = testString.end(); while( boost::regex_search(start, end, what, expression) ) { std::cout<< "Have digit:" ; std::string msg(what[0].first, what[0].second); std::cout<< msg.c_str() << std::endl; start = what[0].second; } } */ //#include "stdafx.h" #include #include #include #include #include using namespace std; //using namespace boost; boost::wregex expression(L"^\\s*我+\\s*[想|爱|恨|扁]+\\s*你"); int main(int argc, char* argv[]) { locale loc( "Chinese-simplified" ); wcout.imbue(loc); std::wstring in = L"我我我我 爱爱爱爱爱 你"; static boost::wsmatch what; cout << "enter test string" << endl; //getline(cin,in); if(boost::regex_match(in.c_str(), what, expression)) { for(int i=0;i #include #include int main() { std::string str = "I'm singing while you're dancing."; std::string pattern = "(\\b\\w+(?=ing\\b))"; boost::regex ee_all(pattern); boost::smatch result; std::string::const_iterator it = str.begin(); std::string::const_iterator end = str.end(); while(boost::regex_search(it, end, result, ee_all)) { std::cout << result[0] << '\n'; it = result[0].second; } } */ /*void main() { std::string testString = "sdfsaaccdf192dfsdbbdd.168sdfs.sdfs4dsf.sfdsd1asfscvasdf"; cmatch what; regex expression( "(?=(.+?))"); if(regex_match(testString,what,expression)) { int sun = what.size(); cout< it(s,s+std::strlen(s),reg,-1); regex_token_iterator end; while (it!=end) { cout<<*it++<

转载于:https://www.cnblogs.com/pcdelphi/archive/2009/07/05/2018015.html

你可能感兴趣的:(c++ boost正则使用)