fork(1) download
  1. #include <string>
  2. #include <iostream>
  3. #include <regex>
  4. using namespace std;
  5.  
  6. int main() {
  7. std::regex rx_extract("[0-9]+");
  8. std::regex rx_validate(R"(^\d+(?:,\d+)*$)");
  9. std::string s = "1,2,3,5";
  10. if (regex_match(s, rx_validate)) {
  11. for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), rx_extract);
  12. i != std::sregex_iterator();
  13. ++i)
  14. {
  15. std::smatch m = *i;
  16. std::cout << m.str() << '\n';
  17. }
  18. }
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 16168KB
stdin
Standard input is empty
stdout
1
2
3
5