fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4. using namespace std;
  5.  
  6. int main() {
  7. std::regex r(R"(\w)");
  8. std::string s("a,b,c,d,e,f,g");
  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. }
  16.  
  17. return 0;
  18. }
  19.  
  20.  
  21.  
Success #stdin #stdout 0s 3544KB
stdin
Standard input is empty
stdout
Match value: a at Position 0
Match value: b at Position 2
Match value: c at Position 4
Match value: d at Position 6
Match value: e at Position 8
Match value: f at Position 10
Match value: g at Position 12