命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | regex‎ | match results
 
 
 
正则表达式库
(C++11)
算法
迭代器
异常
特性
常量
(C++11)
正则表达式语法
 
 
difference_type position( size_type n = 0 ) const;
(C++11 起)

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

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

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

如果 n >= size(),则返回未匹配匹配的首字符位置。

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

目录

[edit] 参数

n - 指定要检查哪个匹配的整数

[edit] 返回值

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

[edit] 示例

#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

[edit] 参见

返回指定的子匹配
(公共成员函数) [编辑]