std::string result; auto iter = std::sregex_iterator(input.begin(), input.end(), pattern); auto end = std::sregex_iterator(); size_t lastPos = 0; for (; iter != end; ++iter) { const std::smatch& match = *iter; result.append(input, lastPos, match.position() - lastPos); // Convert hexadecimal codepoint to integer int codepoint = std::stoi(match[1].str(), nullptr, 16); // Append the Unicode character to the result string result.push_back(static_cast(codepoint)); // Update last position lastPos = match.position() + match.length(); } // Append the rest of the input string result.append(input, lastPos, input.length() - lastPos); return result;