Boost::xpressive regex_search concatenate matches in a single string

67 Views Asked by At

I want to concatenate all matches found by regex_search into a single string, and then return it. I tried doing it with std::accumulate, but failed.

Is there a way to return something like std::accumulate(what.begin()+1, what.end(), someFunc)?
I'm not very familiar with functional programming. I know that I can make a for loop that adds strings together, but I want to try doing it otherwise. Thanks in advance!

Here is a pseudo-code snippet that might help you better understand what I want to do.

std::string foo(const std::string& text) 
{   
    using namespace boost::xpressive;
    sregex srx = +_d >> as_xpr("_") >> +_d; // some random regex
    smatch what;

    if (regex_search(filename, what, srx))
    {
        // Here I want to return a string,
        //  concatenated from what[1].str() + what[2].str() + ... + what[n].str();
        // How do I do this?
        // What about what[1].str() + "-" + what[2].str()...?
    }
    return std::string();
}
0

There are 0 best solutions below