The match pattern is pretty simple: "\{\s*(\w+)\s*\,\s*(\w+)\s*\}" so we just need to loop through and assemble all the matches. C++11 makes this pretty straight forward. Give this a shot:
std::string str = "{1, 2}, {one, two}, {123, onetwothree}";
std::vector<std::pair<std::string, std::string>> pairs;
std::regex exp(R"(\{\s*(\w+)\s*\,\s*(\w+)\s*\})");
std::smatch sm;
std::string::const_iterator cit = str.cbegin();
while (std::regex_search(cit, str.cend(), sm, exp)) {
if (sm.size() == 3) // 3 = match, first item, second item
pairs.emplace_back(sm[1].str(), sm[2].str());
// the next line is a bit cryptic, but it just puts cit at the remaining string start
cit = sm[0].second;
}
EDIT: Explanation on how it works: it matches one pattern at a time, using a constant iterator to point at the remainder after each match:
{1, 2}, {one, two}, {123, onetwothree}
^ iterator cit
-- regex_search matches "{1, 2}" sm[1] == "1", sm[2] == "2"
{1, 2}, {one, two}, {123, onetwothree}
^ iterator cit
-- regex_search matches "{one, two}" sm[1] == "one", sm[2] == "two"
{1, 2}, {one, two}, {123, onetwothree}
^ iterator cit
-- regex_search matches "{123, onetwothree}" sm[1] == "123", sm[2] == "onetwothree"
{1, 2}, {one, two}, {123, onetwothree}
^ iterator cit
-- regex_search returns false, no match