fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <regex>
  4. using namespace std;
  5.  
  6. int main() {
  7. std::regex re(R"((?:^|[^\\])(?:\\{2})*'([^'\\]*(?:\\[\s\S][^'\\]*)*)')");
  8. std::string s("server ('m1.labs.teradata.com') username ('u\\'se)r_*5') password('uer 5') dbname ('default')");
  9. unsigned count = 0;
  10. for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), re);
  11. i != std::sregex_iterator();
  12. ++i)
  13. {
  14. std::smatch m = *i;
  15. cout << "the token is"<<" "<< m.str(1) << endl;
  16. count++;
  17. }
  18. cout << "There were " << count << " tokens found." << endl;
  19. return 0;
  20. }
Success #stdin #stdout 0s 15344KB
stdin
Standard input is empty
stdout
the token is   m1.labs.teradata.com
the token is   u\'se)r_*5
the token is   uer 5
the token is   default
There were 4 tokens found.