public member function
<regex>

std::match_results::size

size_type size() const;
返回匹配数量
返回 match_results 对象中匹配和子匹配的数量。

参数



返回值

对象中匹配(和子匹配)的数量。

成员类型size_type是一种无符号整型类型。

示例

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;
}

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


另见