lundi 18 septembre 2017

c++11 regexp retrieving all groups with +/* modifiers

I don't understand how to retrieve all groups using regexp in c++ An example:

const std::string s = "1,2,3,5";
std::regex lrx("^(\\d+)(,(\\d+))*$");
std::smatch match;
if (std::regex_search(s, match, lrx))
{
    int i = 0;
    for (auto m : match)
        std::cout << "  submatch " << i++ <<  ": "<< m << std::endl;
}

Gives me the result

  submatch 0: 1,2,3,5
  submatch 1: 1
  submatch 2: ,5
  submatch 3: 5

I am missing 2 and 3

Aucun commentaire:

Enregistrer un commentaire