fork(14) download
  1. #include <string>
  2. #include <vector>
  3. #include <iostream>
  4. #include <regex>
  5. using namespace std;
  6.  
  7. int main() {
  8. std::regex r("\"two\":([0-9]*)");
  9. std::vector<int> results;
  10. std::string s = " \"one\":\"1\", \"two\":2, \"three\":3, \"two\":22 ";
  11. for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), r);
  12. i != std::sregex_iterator();
  13. ++i)
  14. {
  15. std::smatch m = *i;
  16. results.push_back(std::stoi( m[1].str().c_str() ));
  17. }
  18. for (auto n: results)
  19. std::cout << n << std::endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 15344KB
stdin
Standard input is empty
stdout
2
22