我正在尝试使用 C++ 中的 Boost::regex 获取字符串内的所有单词。
这是我的输入:
“你好 | 网络 - bla bla hoho”
使用此代码:
regex rgx("[a-z]+",boost::regex::perl|boost::regex::icase);
regex_search(input, result, rgx);
for(unsigned int j=0; j<result.size(); ++j)
{
cout << result[j] << endl;
}
我只得到第一个词“Hello”.. 我的代码有什么问题吗? result.size() 返回 1。
谢谢。
最佳答案
regex_search 仅查找第一个匹配项。要迭代所有匹配项,请使用 regex_iterator
关于c++ - 有关 C++ Boost::regex 的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2592800/