This minimal example shows how to replace strings using the re2 GlobalReplace()
function:
#include <re2/re2.h> #include <iostream> #include <string> using namespace re2; using namespace std; // Pre-compiled regex RE2 myRegex("\\$[^\\$]+\\$"); int main(int argc, char** argv) { string myString = "This string $abc123$ contains two formulas $123 != 456$."; // NOTE: This will modify myString! RE2::GlobalReplace(&myString, myRegex, "FORMULA"); // Prints "This string FORMULA contains two formulas FORMULA." cout << myString << endl; }