fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4. #include <algorithm>
  5.  
  6. int main()
  7. {
  8. std::string tekst = "<b>to jest </b> testowy napis <b>:)";
  9. std::regex spaces("[ ]+");
  10. std::transform(tekst.begin(), tekst.end(), tekst.begin(),
  11. [](char c) -> char { return c == '<' || c == '>' ? c + '[' - '<' : c; });
  12. std::cout << std::regex_replace(tekst, spaces, " ") << std::endl;
  13. return 0;
  14. }
Success #stdin #stdout 0s 3560KB
stdin
Standard input is empty
stdout
[b]to jest [/b] testowy napis [b]:)