Namespaces
Variants

std::match_results<BidirIt,Alloc>:: size

From cppreference.net
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
Exceptions
Traits
Constants
(C++11)
Regex Grammar
size_type size ( ) const noexcept ;
(自 C++11 起)

返回子匹配的数量,即 std:: distance ( begin ( ) , end ( ) )

* this 不表示成功匹配的结果,则返回 0

目录

参数

(无)

返回值

子匹配的数量。

复杂度

常量。

示例

#include <iostream>
#include <regex>
#include <string>
int main()
{
    std::regex re("a(a)*b");
    std::string target("aaab");
    std::smatch sm;
    std::cout << sm.size() << '\n';
    std::regex_match(target, sm, re);
    std::cout << sm.size() << '\n';
}

输出:

0
2

参见

返回指向子匹配列表起始位置的迭代器
(公开成员函数)
返回指向子匹配列表末尾位置的迭代器
(公开成员函数)