The goal is: This json:
{"secretWord1":"private", "something": "\"secretWord2\":\"privateToo\""}
Convert to this by regex_match:
{"secretWord1":"****", "something": "\"secretWord2\":\"****\""}
I have a following code with three regex expression:
std::regex regex1(R"~((\\\"|")((?:[^\\"]*)(?:secretWord1|secretWord2))\1:\1([^\\"]*)\1)~", std::regex_constants::icase);
std::regex regex2(R"~((\\\")((?:[^\\"]*)(?:secretWord1|secretWord2))\1:\1([^\\"]*)\1)~", std::regex_constants::icase);
std::regex regex3(R"~((")((?:[^\\"]*)(?:secretWord1|secretWord2))\1:\1([^\\"]*)\1)~", std::regex_constants::icase);
std::string replaced = someJsonData;
replaced = std::regex_replace(replaced, regex1, "$1$2$1:$1****$1");
replaced = std::regex_replace(std::regex_replace(replaced, regex2, "$1$2$1:$1****$1"), regex3, "$1$2$1:$1****$1");
I want to replace secret information and hide it behind stars. The first regex fails on
error_stack: regex_error(error_stack): There was insufficient memory to determine whether the regular expression could match the specified character sequence.
Is there something wrong with the first expression? Because the other two expressions just complement each other and in the end, it does the same job like the regex1 but they work well when I run them.
I can't povide a sample code during it fails but the file isn't so big (around 30kB). And when I tried it with JSON generator the regex1 is obviously slower than when I combine regex2+regex3.