std::match_results<BidirIt,Alloc>::position
来自 cppreference.cn
< cpp | regex | match results
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] 参见
返回指定的子匹配 (公共成员函数) |