public member function
<regex>

std::regex_token_iterator::regex_token_iterator

default (1)
regex_token_iterator();
copy (2)
regex_token_iterator (const regex_token_iterator& rti);
single submatch (3)
regex_token_iterator ( BidirectionalIterator first, BidirectionalIterator last,        const regex_type& rgx,        int submatch = 0,        regex_constants::match_flag_type flags = regex_constants::match_default);
vector of submatches (4)
regex_token_iterator ( BidirectionalIterator first, BidirectionalIterator last,        const regex_type& rgx,        const vector<int>& submatches,        regex_constants::match_flag_type flags = regex_constants::match_default);
initializer_list of submatches (5)
regex_token_iterator ( BidirectionalIterator first, BidirectionalIterator last,        const regex_type& rgx,        initializer_list<int> submatches,        regex_constants::match_flag_type flags = regex_constants::match_default);
array of submatches (6)
template <size_t N>  regex_token_iterator ( BidirectionalIterator first, BidirectionalIterator last,        const regex_type& rgx,        const int (&submatches)[N],        regex_constants::match_flag_type flags = regex_constants::match_default);
default (1)
regex_token_iterator();
copy (2)
regex_token_iterator (const regex_token_iterator& rti);
single submatch (3)
regex_token_iterator ( BidirectionalIterator first, BidirectionalIterator last,        const regex_type& rgx,        int submatch = 0,        regex_constants::match_flag_type flags = regex_constants::match_default);
vector of submatches (4)
regex_token_iterator ( BidirectionalIterator first, BidirectionalIterator last,        const regex_type& rgx,        const vector<int>& submatches,        regex_constants::match_flag_type flags = regex_constants::match_default);
initializer_list of submatches (5)
regex_token_iterator ( BidirectionalIterator first, BidirectionalIterator last,        const regex_type& rgx,        initializer_list<int> submatches,        regex_constants::match_flag_type flags = regex_constants::match_default);
array of submatches (6)
template <size_t N>  regex_token_iterator ( BidirectionalIterator first, BidirectionalIterator last,        const regex_type& rgx,        const int (&submatches)[N],        regex_constants::match_flag_type flags = regex_constants::match_default);
deleted overloads (7)
   /* additional overloads taking a const regex_type&& as third argument */
Construct regex_token_iterator
Constructs a regex_token_iterator object.

The default constructor (1) constructs an end-of-sequence iterator. This value shall not be dereferenced.

The copy constructor (2) copies the value of iterator rti.

The initialization constructors (3), (4), (5) and (6) attempt a first match as if regex_search was called with the corresponding arguments. If this match is successful, the iterator keeps the state of the search and becomes a dereferenceable iterator pointing to a valid sub_match object that describes the range of the first selected submatch in the sequence. If no matches are found, the object is set to the end-of-sequence value, as if default-constructed.

The additional overloads (7) have the same signatures as the initialization constructors (3), (4), (5) and (6) but they take an r-value reference (const regex_type&&) as third argument. These overloads are defined as deleted, preventing the construction with temporaries.

The argument submatch or submatches is used to select which submatches of each match the iterator has to iterate through.

Parameters

rti
Another object of the same regex_token_iterator type (with the same template parameters).
first, last
Bidirectional iterators to the initial and final positions in the range of characters used as target sequence for the search. The range used is [first,last), which includes all the characters between first and last, including the character pointed by first but not the character pointed by last.
BidirectionalIterator is the first class template parameter, that shall be bidirectional iterator to characters.
rgx
A basic_regex object (the pattern) to match.
Note: the iterator does not keep a copy of this object (only a reference), therefore this should not be a temporary value.
regex_type is a member type, defined as an alias of the basic_regex type corresponding to the class template parameters.
submatch
The sub_match to be selected on each position of the iterator.
If this is 0, the entire match is selected.
If this is -1, the section of the sequence that is not matched is selected, using the match as separator.
submatches
Same as above, except that, if there are more that one int passed, the iterator will need to be advanced as many times to get to the next match, selecting on each instance the corresponding submatch (see regex_token_iterator::operator++).
flags
Flags used to control how rgx is matched.
One or more of these constants can be combined (using the bitwise OR operator, |) to form a valid bitmask value of type regex_constants::match_flag_type:
flag*effects on matchnotes
match_defaultDefaultDefault matching behavior.
This constant has a value of zero**.
match_not_bolNot Beginning-Of-LineThe first character is not considered a beginning of line ("^" does not match).
match_not_eolNot End-Of-LineThe last character is not considered an end of line ("$" does not match).
match_not_bowNot Beginning-Of-WordThe escape sequence "\b" does not match as a beginning-of-word.
match_not_eowNot End-Of-WordThe escape sequence "\b" does not match as an end-of-word.
match_anyAny matchAny match is acceptable if more than one match is possible.
match_not_nullNot nullEmpty sequences do not match.
match_continuousContinuousThe expression must match a sub-sequence that begins at the first character.
Sub-sequences must begin at the first character to match.
match_prev_availPrevious AvailableOne or more characters exist before the first one. (match_not_bol and match_not_bow are ignored)
format_defaultDefaultSame as match_default.
This constant has a value of zero**.
format_sedNoneIgnored by this object.
See regex_constants for more info.
format_no_copy
format_first_only
* These bitmask flag names are available under the std::regex_constants namespace (see regex_constants for more details).
** Constants with a value of zero are ignored if some other flag is set.
match_flag_type is a type available under the std::regex_constants namespace.


Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 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"

  // default constructor = end-of-sequence:
  std::regex_token_iterator<std::string::iterator> rend;

  std::cout << "entire matches:"; 
  std::regex_token_iterator<std::string::iterator> a ( s.begin(), s.end(), e );
  while (a!=rend) std::cout << " [" << *a++ << "]";
  std::cout << std::endl;

  std::cout << "2nd submatches:";
  std::regex_token_iterator<std::string::iterator> b ( s.begin(), s.end(), e, 2 );
  while (b!=rend) std::cout << " [" << *b++ << "]";
  std::cout << std::endl;

  std::cout << "1st and 2nd submatches:";
  int submatches[] = { 1, 2 };
  std::regex_token_iterator<std::string::iterator> c ( s.begin(), s.end(), e, submatches );
  while (c!=rend) std::cout << " [" << *c++ << "]";
  std::cout << std::endl;

  std::cout << "matches as splitters:";
  std::regex_token_iterator<std::string::iterator> d ( s.begin(), s.end(), e, -1 );
  while (d!=rend) std::cout << " [" << *d++ << "]";
  std::cout << std::endl;

  return 0;
}

Output:
entire matches: [subject] [submarine] [subsequence]
2nd submatches: [ject] [marine] [sequence]
1st and 2nd submatches: [sub] [ject] [sub] [marine] [sub] [sequence]
matches as splitters: [this ] [ has a ] [ as a ]


See also