fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <regex>
  5.  
  6. int main() {
  7. std::regex rx(R"(\b(?!(?:word1|word2)\b)\w+)");
  8. std::string s = "Extract all words but word1 and word2.";
  9. std::vector<std::string> results(std::sregex_token_iterator(s.begin(), s.end(), rx),
  10. std::sregex_token_iterator());
  11.  
  12. for( auto & p : results ) std::cout << p << std::endl;
  13. return 0;
  14. }
Success #stdin #stdout 0s 4472KB
stdin
Standard input is empty
stdout
Extract
all
words
but
and