命名空间
变体
操作

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

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

获取对 std::sub_match 对象的引用,该对象表示目标序列的开头到整个正则表达式匹配的开头之间的目标序列。

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

[编辑] 返回值

对未匹配前缀的引用。

[编辑] 示例

#include <iostream>
#include <regex>
#include <string>
 
int main()
{
    std::regex re("a(a)*b");
    std::string target("baaaby");
    std::smatch sm;
 
    std::regex_search(target, sm, re);
    std::cout << sm.prefix().str() << '\n';
}

输出

b

[编辑] 参见

返回完整匹配结束和目标序列结束之间的子序列
(公共成员函数) [编辑]