Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::regex r(R"((b[[:alpha:]]+b)|(bd+b))");
- std::string s = "foo bar 123";
- for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), r);
- i != std::sregex_iterator();
- ++i)
- {
- std::smatch m = *i;
- std::cout << "Match value: " << m.str() << " at Position " << m.position() << 'n';
- for(auto index = 1; index < m.size(); ++index ){
- if (!m[index].str().empty()) {
- std::cout << "Capture group ID: " << index-1 << std::endl;
- }
- }
- }
- Match value: foo at Position 0
- Capture group ID: 0
- Match value: bar at Position 4
- Capture group ID: 0
- Match value: 123 at Position 8
- Capture group ID: 1
Add Comment
Please, Sign In to add comment