1234567891011121314
#include <iostream> #include <string> #include <regex> std::string add_spaces( const std::string& text, const std::regex& re ) { // " $& " - space, a copy of the match, space return std::regex_replace( text, re, " $& " ) ; } int main() { std::cout << '"' << add_spaces( "abcdxyzefghxyzijklxyzmnop", std::regex("xyz") ) << "\"\n" ; }