名稱空間
變體
操作

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

來自 cppreference.com
< 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。否則,行為未定義。

目錄

[編輯] 引數

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

[編輯] 另請參閱

返回指定的子匹配
(公共成員函式) [編輯]