gpt4 book ai didi

c++ - 帮助 C++ Boost::regex

转载 作者:搜寻专家 更新时间:2023-10-31 00:23:02 25 4
gpt4 key购买 nike

我试图在 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;
}

我只得到第一个词“你好”..我的代码有什么问题? result.size() 返回 1。

谢谢。

最佳答案

regex_search 只找到第一个匹配项。要遍历所有匹配项,请使用 regex_iterator

关于c++ - 帮助 C++ Boost::regex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2592800/

25 4 0
文章推荐: c++ - 风格问题
文章推荐: c++ - 图形编程
文章推荐: c++ - C++对象之间的通信
文章推荐: c++ - 在 C++ 中解析本地时间
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com