public member function
<regex>

std::regex_iterator::operator++

(1)
regex_iterator& operator++();
(2)
regex_iterator& operator++(int);
Increment regex_iterator
Advances the regex_iterator to the next match.

The function performs a new search on the remainder of the target sequence, filling its internal match_results accordingly as if the function called regex_search on (*this)->suffix(), but with the match flags altered:
  • if the most recent match was not an empty subsequence, the match flags include match_prev_avail.
  • otherwise, the match flags include match_not_null and match_continuous.

Except that the positions (see match_results::position) are relative to the beginning of the entire target sequence and not only to the beginning of (*this)->suffix() [Note: assumption, 14882:2011-28.12.1.4].

After a call to this function, if such a call to regex_search would have returned true, a dereference of the iterator returns a reference to the internal match_results object. Otherwise, it returns an end-of-sequence iterator value.

A specific implementation of this function in a library may not necessarily call the regex_search function at all, and instead use its own internal algorithm to perform the searches.

Parameters

none (the second version is for the post-increment operator).

Return value

The pre-increment version (1) returns *this.
The post-increment version (2) returns a copy of the value of *this before the call.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// regex_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_iterator<std::string::iterator> rit ( s.begin(), s.end(), e );
  std::regex_iterator<std::string::iterator> rend;

  while (rit!=rend) {
    std::cout << rit->str() << std::endl;
    ++rit;
  }

  return 0;
}

Output:
subject
submarine
subsequence



See also