public member function
<regex>
const value_type* operator->() const;
Dereference regex_token_iterator
Returns a pointer to the sub_match subsequence the iterator is pointing to.
The pointer is generally used to access a member of that object directly using the built-in operator-> syntax.
This operator shall not be applied to end-of-sequence iterators (the behavior of such an operation is undefined).
regex_token_iterator objects keep a regex_iterator object internally. A pointer to one of its sub_match elements is returned by a call to this function. But, the state of this internal regex_iterator object that contains the submatch may be modified by a call to either operator++ or operator= on the regex_token_iterator object, which can invalidate the element pointed by the returned pointer.
Return value
A pointer to the sub_match object selected by the regex_token_iterator.
value_type is a member type defined as the instantiation of sub_match corresponding to the class template parameters.
Example
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->str() << std::endl;
++rit;
}
return 0;
}
|
Output: