场景:
1.比如在html中查找出现过的标签,好提取图片地址.
2.编译器不支持C++11标准时使用boost库是比较好的选择.
例子:
#include
#include
#include
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
std::string str("infoasdf123unil98oasdfa686^&*(432");
boost::regex e1("[0-9]+");
std::string::const_iterator start, end;
start = str.begin();
end = str.end();
boost::match_results what;
boost::match_flag_type flags = boost::match_default;
while(regex_search(start, end, what, e1, flags))
{
cout << "finded number: " << string(what[0].first,what[0].second) << endl;
start = what[0].second;
}
return 0;
}
//http://www.boost.org/doc/libs/1_46_1/libs/regex/doc/html/boost_regex/ref/regex_search.html