#include <string> #include <regex> std::string test = "abc def abc def"; test = std::regex_replace(test, std::regex("def"), "klm"); // replace 'def' -> 'klm' // test = "abc klm abc klm"