public member function
<regex>

std::match_results::size

size_type size() const;
Return number of matches
Returns the number of matches and sub-matches in the match_results object.

Parameters

none

Return value

The number of matches (and sub-matches) in the object.

Member type size_type is an unsigned integral type.

Example

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

int main ()
{
  std::string mystring ("subject");
  std::smatch mymatches;
  std::regex myregex ("(sub)(.*)");

  std::regex_match ( mystring, mymatches, myregex );

  std::cout << mymatches.size() << " matches found:" << std::endl;
  for (unsigned i=0; i<mymatches.size(); ++i)
    std::cout << "match #" << i << ": " << mymatches[i] << std::endl;

  return 0;
}

Output:
3 matches found:
match #0: subject
match #1: sub
match #2: ject


See also