Namespaces
Variants

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

From cppreference.net
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
Exceptions
Traits
Constants
(C++11)
Regex Grammar
difference_type position ( size_type n = 0 ) const ;
(自 C++11 起)

返回指定子匹配项首字符的位置。

如果 n == 0 ,则返回整个匹配表达式第一个字符的位置。

如果 n > 0 && n < size ( ) ,则返回第 n 个子匹配项首字符的位置。

如果 n >= size ( ) ,则返回未匹配部分的第一个字符位置。

ready() 必须为 true 。否则行为是未定义的。

目录

参数

n - 用于指定要检查的匹配项的整数值

返回值

指定匹配或子匹配的首字符位置。

示例

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

输出:

2

参见

返回指定的子匹配
(公开成员函数)