I have such text, which contains a list pair, and every pair contains a list of some data and the connection of that data to some other data:
{data={data1,data2},connection=data3}, {{data4},data5}, {{data6},data7}, ...
I need to extract the data entry from each pair, i.e. I need data1
, data2
, data3
etc.
This is the regexp I came up with:
(\{(?:\S*=)?\{\S+\})(?:,(?:\S*=)?\}\S+)?
regex101.com matches the pattern to the text and separates the string into these groups:
{data={data1,data2},connection=data3}
, {{data4},data5}
, {{data6},data7}
(for each of which I'll need to run another regexp). However, my C++ doesn't doesn't match the string:
#include <iostream>
#include <string>
#include <regex>
int main()
{
std::string text{ "{data={data1,data2},connection=data3}, {{data4},data5}, {{data6},data7}" };
const std::regex rx{ R"data((\{\S*\{\S+\})(?:,(\S*=)?\}\S+)?)data" };
std::smatch matches;
if (std::regex_match(text, matches, rx))
{
std::cout << matches.size() << std::endl;
}
system("pause");
}
How should I do this in C++?