fork download
  1. #include <iostream>
  2. #include <regex>
  3. #include <string>
  4.  
  5. int main() {
  6.  
  7. std::vector<std::string> text = {
  8. "Hello ! What the foundation will do is...",
  9. "Hello! What a talented foundation will do is...",
  10. "water, take, food",
  11. "what you take for",
  12. "Well! The food is not good!"
  13. };
  14.  
  15. auto wtf_ex = std::regex{R"(\b[wW]+[\w]*[\W]+[tT]+[\w]*[\W]+[fF]+[\w]*)"};
  16.  
  17.  
  18. for (const auto& unmodified : text) {
  19. auto modified =
  20. std::regex_replace(unmodified, wtf_ex, "WTF");
  21.  
  22. std::cout << "\n\nUnmodified: " << unmodified;
  23. std::cout << "\nModified: " << modified;
  24. }
  25. }
Success #stdin #stdout 0s 15344KB
stdin
Standard input is empty
stdout

Unmodified: Hello ! What the foundation will do is...
Modified:   Hello ! WTF will do is...

Unmodified: Hello! What a talented foundation will do is...
Modified:   Hello! What a talented foundation will do is...

Unmodified: water, take, food
Modified:   WTF

Unmodified: what you take for
Modified:   what you take for

Unmodified: Well! The food is not good!
Modified:   WTF is not good!