fork(42) download
  1. #include <string>
  2. #include <iostream>
  3. #include <regex>
  4. using namespace std;
  5.  
  6. int main() {
  7. std::regex r("ab(c)");
  8. std::string s = "abcdefabcghiabc";
  9. for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), r);
  10. i != std::sregex_iterator();
  11. ++i)
  12. {
  13. std::smatch m = *i;
  14. std::cout << "Match value: " << m.str() << " at Position " << m.position() << '\n';
  15. std::cout << " Capture: " << m[1].str() << " at Position " << m.position(1) << '\n';
  16. }
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 3548KB
stdin
Standard input is empty
stdout
Match value: abc at Position 0
    Capture: c at Position 2
Match value: abc at Position 6
    Capture: c at Position 8
Match value: abc at Position 12
    Capture: c at Position 14