public member function
<regex>

std::regex_iterator::regex_iterator

default (1)
regex_iterator();
copy (2)
regex_iterator (const regex_iterator& rit);
initialization (3)
regex_iterator ( BidirectionalIterator first, BidirectionalIterator last,        const regex_type& rgx,        regex_constants::match_flag_type flags = regex_constants::match_default);
default (1)
regex_iterator();
copy (2)
regex_iterator (const regex_iterator& rit);
initialization (3)
regex_iterator ( BidirectionalIterator first, BidirectionalIterator last,        const regex_type& rgx,        regex_constants::match_flag_type flags = regex_constants::match_default);
moving (deleted) (4)
regex_iterator ( BidirectionalIterator, BidirectionalIterator,        const regex_type&&,        regex_constants::match_flag_type = regex_constants::match_default) = delete;
Construct regex_iterator
Constructs a regex_iterator object.

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

The copy constructor (2) copies the iterator.

The initialization constructor (3) attempts 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 match_results object with information about the match. If no matches are found, the object is set to the end-of-sequence value, as if default-constructed.

Deleting the signature with a moving regex (4) prevents the construction with a temporary regex object.

Parameters

rit
Another object of the same regex_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.
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 match_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
// regex_iterator constructor
#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