lundi 29 janvier 2018

c++ 11 regex print all groups

My question is really simple, I can't make c++ 11 regex to return all groups present in the string.

code below is what I'm using:

#include <iostream>
#include <regex>

int main()
{
  auto fixMessage("8=FIXT|9=69|35=5|34=18|49=102|56=asd|115=TESTTESTTEST|52=20170810-15:36:22.500867816|1409=42|");
  std::regex e ("(([0-9]+)=(.*?)\\|)+?");
  std::cmatch element_match;

  if(std::regex_match(fixMessage, element_match, e)) {
        for (size_t i = 0; i < element_match.size(); ++i) {
            std::cout << i << ": " << element_match[i] << '\n';
        }
  }
  return 0;
}

this only prints this

0: 8=FIXT|9=69|35=5|34=18|49=102|56=asd|115=TESTTESTTEST|52=20170810-15:36:22.500867816|1409=42|
1: 1409=42|
2: 1409
3: 42

while I would like to have all groups not just the last one .. here is a cpp.sh url

Aucun commentaire:

Enregistrer un commentaire