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