0

Let say I've a string of comma separated UUIDs with some additional words as shown below.

DATA_TYPE_1(62af4205-fbf8-4961-902e-0b9b21d82a20,1697700f-7bb3-4f7c-83ba-1933b98e05cd,4595ef3f-34e5-4bbe-9c56-26e4e6c84e9f) 

So the code should return a list of 3 strings in this case consisting the 3 uuids. I tried a code as follows with a vain.

std::vector<std::string> ParseUUIDList(std::string& iText)
{
  std::smatch sm;
  const std::regex pattern("^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$");
  //std::regex_match(iText, sm, pattern);
  while (std::regex_search(iText, sm, pattern)) {
    for (auto x : sm) std::cout << x << " ";
    std::cout << std::endl;
    iText = sm.suffix().str();
  }
  std::vector<std::string> res;
  for (unsigned i = 0; i < sm.size(); ++i) {
    res.push_back(sm[i].str());
  }
  return res;
}

Is there a way to get the UUIDs directly using some regex magic of latest C++. I've seen this article which works for a single uuid but not having a string with multiple.

Enlico
  • 12,203
  • 5
  • 28
  • 59
Suhasis
  • 611
  • 6
  • 11
  • 1
    `^` means *start of string* and `$` means *end of string*. [Remove them](https://ideone.com/C1470B). Or [replace with word boundaries](https://ideone.com/swhvNb). – Wiktor Stribiżew Apr 26 '21 at 08:23

0 Answers0