Boost C++ regex - how to return all matches

后端 未结 1 1314
执笔经年
执笔经年 2021-01-07 01:34

I have and string \"SolutionAN ANANANA SolutionBN\" I want to return all string which start with Solution and end with N.

Whi

相关标签:
1条回答
  • 2021-01-07 02:02

    The problem is that * is greedy. Change to using the non-greedy version (note the ?):

    int main(int ac,char* av[])
    {
        std::string strTotal("SolutionAN ANANANA SolutionBN");
        boost::regex regex("Solu(.*?)N");
    
        boost::sregex_token_iterator iter(strTotal.begin(), strTotal.end(), regex, 0);
        boost::sregex_token_iterator end;
    
        for( ; iter != end; ++iter ) {
               std::cout<<*iter<<std::endl;
        }
    }
    
    0 讨论(0)
提交回复
热议问题