How build a regex from a string variable, and interpret that as Raw format.
std::regex re{R"pattern"};
For the above code, is there a way to replace the fixed string "pattern"
with a std::string pattern;
variable that is either built from compile time or run time.
I tried this but didn't work:
std::string pattern = "key";
std::string pattern = std::string("R(\"") + pattern + ")\"";
std::regex re(pattern); // does not work as if it should when write re(R"key")
Specifically, the if using re(R("key")
the result is found as expected. But building using re(pattern)
with pattern is exactly the same value ("key")
, it did not find the result.
This is probably what I need, but it was for Java, not sure if there is anything similar in C++: