fork download
  1. #include <iostream>
  2. #include <regex>
  3. using namespace std;
  4.  
  5. int main() {
  6. string str = "11101010101011101";
  7. regex rx("(01)+", std::regex::extended);
  8.  
  9. vector<pair<int, int>> index_matches; // results saved here
  10.  
  11.  
  12. for(auto it = std::sregex_iterator(str.begin(), str.end(), rx); it != std::sregex_iterator(); ++it) {
  13.  
  14. std::smatch match = *it;
  15. index_matches.push_back(make_pair<int, int>(it->position(), it->position() + match.length() -1));
  16. }
  17.  
  18. for(auto n: index_matches)
  19. std::cout << "(" << n.first << ", " << n.second << ")" << std::endl;
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 16168KB
stdin
Standard input is empty
stdout
(3, 12)
(15, 16)