public member function
<regex>

std::basic_regex::mark_count

unsigned mark_count() const;
Return number of marked sub-expressions
Returns the number of explicitly marked sub-expressions in the basic_regex.
This corresponds to the number of sub-expressions that should be captured in a match_results object used with this basic_regex object, but without including the eventual match of the whole expression (only the in-parentheses sub-expressions are counted).

Parameters

none

Return value

The number of marked sub-expressions.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// basic_regex::mark_count
// note: using regex, a standard alias of basic_regex<char>
#include <iostream>
#include <regex>

int main ()
{
  std::regex myregex ("(sub)([a-z]*).*");
  std::cout << "The pattern captures " << myregex.mark_count() << " sub-expressions.\n";

  std::cmatch m;
  regex_match ("subject", m, myregex);

  if ( m.size() == myregex.mark_count() + 1 ) {
    std::cout << "Ok, all sub-expressions captured.\n";
    std::cout << "Matched expression: " << m[0] << "\n";
    for (unsigned i=1; i<m.size(); ++i) 
	  std::cout << "Sub-expression " << i << ": " << m[i] << "\n";
  }

  return 0;
}


Output:
The pattern captures 2 sub-expressions.
Ok, all sub-expressions captured.
Matched expression: subject
Sub-expression 1: sub
Sub-expression 2: ject

See also