1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
// regex_token_iterator example
#include <iostream>
#include <string>
#include <regex>
int main ()
{
std::string s ("this subject has a submarine as a subsequence");
std::regex e ("\\b(sub)([^ ]*)"); // matches words beginning by "sub"
std::regex_token_iterator<std::string::iterator> rend; // end-of-sequence iterator
// iterate over second submatches of each match:
std::regex_token_iterator<std::string::iterator> rit ( s.begin(), s.end(), e, 2 );
while (!(rit==rend)) {
std::cout << *rit << std::endl;
++rit;
}
return 0;
}
|