public member function
<regex>

std::match_results::begin

const_iterator begin() const;
Return iterator to beginning
Returns an iterator pointing to the first match in the match_results object. Together with match_results::end, these functions describe a range that encompasses all the matches in the match_results object.

Notice that, if the expression matched, the first match in the range always represents the entire matched sequence of characters. Subsequent matches in the range represent individual sub-expressions, if they were explicitly requested in the regex object.

If the match_results object is empty (i.e., the expression did not match), the value returned by begin is the same as the one returned by end, representing an empty range, and shall not be dereferenced.

If the match_results object is not ready, the value returned by this function may bear no relation with that of end, and thus shall not be used to specify a range. It shall neither be dereferenced.

Parameters

none

Return value

An iterator to to the sub_match object describing the first match in the match_results object.

Member type const_iterator (the same as member type iterator) is a forward iterator type.
The matches contained in a match_results object are always const.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// match_results::begin/end
// - using smatch, a standard alias of match_results<string::iterator>
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  std::string s ("subject");
  std::smatch m;
  std::regex e ("(sub)(.*)");

  std::regex_match ( s, m, e );

  std::cout << "matches:" << std::endl;
  for (std::smatch::iterator it = m.begin(); it!=m.end(); ++it) {
	std::cout << *it << std::endl;
  }
  return 0;
}

Output:
matches:
subject
sub
ject



See also