我的代码是:
#include <boost/regex.hpp>
boost::cmatch matches;
boost::regex_match("alpha beta", matches, boost::regex("([a-z])+"));
cout << "found: " << matches.size() << endl;
Run Code Online (Sandbox Code Playgroud)
并且它显示found: 2
哪个意味着只找到一个事件......如何指示它找到三个事件?谢谢!
这是我到目前为止发现的:
text = "alpha beta";
string::const_iterator begin = text.begin();
string::const_iterator end = text.end();
boost::match_results<string::const_iterator> what;
while (regex_search(begin, end, what, boost::regex("([a-z]+)"))) {
cout << string(what[1].first, what[2].second-1);
begin = what[0].second;
}
Run Code Online (Sandbox Code Playgroud)
它按预期工作。也许有人知道更好的解决方案?
归档时间: |
|
查看次数: |
1588 次 |
最近记录: |