#include <iostream>
#include <string>
#include <vector>
#include <regex>

int main() {
	std::regex rx(R"(\b(?!(?:word1|word2)\b)\w+)");
	std::string s = "Extract all words but word1 and word2.";
	std::vector<std::string> results(std::sregex_token_iterator(s.begin(), s.end(), rx),
                               std::sregex_token_iterator());
	
    for( auto & p : results ) std::cout << p << std::endl;
    return 0;
}