std::match_results::position
| difference_type position( size_type n = 0 ) const; |  | (since C++11) | 
|---|
返回指定子匹配的第一个字符的位置。
如果n == 0,返回整个匹配表达式的第一个字符的位置。
如果n > 0 && n < size(),返回_n_th子匹配的第一个字符的位置。
如果n >= size(),返回不匹配匹配的第一个字符的位置。
参数
| n | - | integral number specifying which match to examine | 
|---|
返回值
指定匹配或子匹配的第一个字符的位置。
例
二次
#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';
}二次
产出:
二次
1二次
另见
| operator[] | returns specified sub-match (public member function) | 
|---|
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

