fork download
  1. #include<iostream>
  2. #include<regex>
  3. using namespace std;
  4.  
  5. int main() {
  6. string s = "foo:12,bar:456,b:az:0,";
  7. regex c("([^,]+?):([0-9]+)");
  8. int matches = 0;
  9. smatch sm;
  10. sregex_iterator iter(s.begin(), s.end(), c); std::sregex_iterator end;
  11. while(iter != end) {
  12. sm = *iter;
  13. cout << "grp1 - " << sm[1].str() << ", grp2 - " << sm[2].str() << endl;
  14. matches++;
  15. ++iter;
  16. }
  17. cout << "Matches: " << matches << endl;
  18. }
Success #stdin #stdout 0.01s 5432KB
stdin
Standard input is empty
stdout
grp1 - foo,   grp2 - 12
grp1 - bar,   grp2 - 456
grp1 - b:az,   grp2 - 0
Matches: 3