fork(6) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <regex>
  5. using namespace std;
  6.  
  7. int main() {
  8. std::regex rx(R"(&&|\|\||[();])");
  9. std::string exp = "a < b | c | d > e >> f && ((g) || h) ; i";
  10. std::sregex_token_iterator srti(exp.begin(), exp.end(), rx, {-1, 0});
  11. std::vector<std::string> tokens;
  12. std::remove_copy_if(srti, std::sregex_token_iterator(),
  13. std::back_inserter(tokens),
  14. [](std::string const &s) { return s.empty(); });
  15. for( auto & p : tokens ) std::cout <<"'"<< p <<"'"<< std::endl;
  16. return 0;
  17. }
Success #stdin #stdout 0s 4432KB
stdin
Standard input is empty
stdout
'a < b | c | d > e >> f '
'&&'
' '
'('
'('
'g'
')'
' '
'||'
' h'
')'
' '
';'
' i'