#include <iostream>
#include <string>
#include <regex>
#include <algorithm>

int main()
{
    std::string tekst = "<b>to jest </b> testowy       napis     <b>:)";
    std::regex spaces("[ ]+");
    std::transform(tekst.begin(), tekst.end(), tekst.begin(),
        [](char c) -> char { return c == '<' || c == '>' ? c + '[' - '<' : c; });
    std::cout << std::regex_replace(tekst, spaces, " ") << std::endl;
    return 0;
}