fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <regex>
  4. #include <string>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. string input {"Again this is the example in which shall be searched"};
  11.  
  12. string first {"again"};
  13. string second {"be"};
  14.  
  15. vector<string> words;
  16. words.push_back("this");
  17. words.push_back("table");
  18.  
  19.  
  20. 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.*).*|.)*?" + second + "\\b", regex_constants::icase);
  21. smatch sm;
  22.  
  23. if (regex_search(input, sm, re) && sm[1].length() == 0U) {
  24. cout << "match\n";
  25. } else {
  26. cout << "not a match\n";
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 3556KB
stdin
Standard input is empty
stdout
not a match