如题 同样给的正则表达式,同样的测试文本,stl正则速度很慢,目前解决办法是用boost的正则表达式后速度提升不少 代码如下
// header file
#include <boost\regex.hpp>
//
static boost::wregex expression(L"[a-zA-Z_0-9-]+(\\.[a-zA-Z0-9-]+)*@([a-zA-Z0-9])+(\\.[a-zA-Z0-9-]+)+");
//boost::wsmatch what;
wstring::iterator start = str_in.begin();
wstring::iterator end = str_in.end();
boost::match_results<wstring::iterator> what;
//boost::wsmatch
boost::match_flag_type flags = boost::match_default;
//bool b = boost::regex_search(str_in, what, expression);
// exist exception
try
{
while (boost::regex_search(start, end, what, expression, flags))
{
//if (what[0].matched)
//{
vStr_out.push_back(what[0]);
//}
// update search position:
start = what[0].second;
// update flags:
flags |= boost::match_prev_avail;
flags |= boost::match_not_bob;
}
}
catch (CMemoryException* e)
{
return;
}
catch (CFileException* e)
{
return;
}
catch (boost::exception& e)
{
return;
}