Guest User

Untitled

a guest
Jan 12th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. std::regex r(R"((b[[:alpha:]]+b)|(bd+b))");
  2. std::string s = "foo bar 123";
  3. for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), r);
  4. i != std::sregex_iterator();
  5. ++i)
  6. {
  7. std::smatch m = *i;
  8. std::cout << "Match value: " << m.str() << " at Position " << m.position() << 'n';
  9.  
  10. for(auto index = 1; index < m.size(); ++index ){
  11. if (!m[index].str().empty()) {
  12. std::cout << "Capture group ID: " << index-1 << std::endl;
  13. }
  14. }
  15. }
  16.  
  17. Match value: foo at Position 0
  18. Capture group ID: 0
  19. Match value: bar at Position 4
  20. Capture group ID: 0
  21. Match value: 123 at Position 8
  22. Capture group ID: 1
Add Comment
Please, Sign In to add comment