Namespaces
Variants

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

From cppreference.net
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
Exceptions
Traits
Constants
(C++11)
Regex Grammar
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

参见

返回完整匹配结束位置与目标序列结束位置之间的子序列
(公开成员函数)