fork download
  1. #include <iostream>
  2. #include <numeric>
  3. #include <regex>
  4. #include <string>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. const auto first = "Somebody"s;
  11. const auto second = "words"s;
  12. const vector<string> words = { "in"s, "lorem"s, "ipsum"s };
  13. const auto input = "Somebody has typed in some words here."s;
  14. const regex re("\\b" + first + accumulate(next(cbegin(words)), cend(words), "\\b(?:(\\b" + words.front(), [](const auto& lhs, const auto& rhs) { return lhs + "\\b|\\b" + rhs; }) + "\\b).*|.)*?\\b" + second + "\\b");
  15. smatch sm;
  16.  
  17. if (regex_search(input, sm, re) && sm[1].length() == 0U) {
  18. cout << "match\n";
  19. } else {
  20. cout << "not a match\n";
  21. }
  22. }
Success #stdin #stdout 0s 3556KB
stdin
Standard input is empty
stdout
not a match