“cpp/regex/match results/prefix”的版本间的差异
来自cppreference.com
< cpp | regex | match results
YexuanXiao(讨论 | 贡献) 小 |
小 |
||
第8行: | 第8行: | ||
{{cpp/precondition|{{rlpf|ready}} 必须为 {{c|true}}。}} | {{cpp/precondition|{{rlpf|ready}} 必须为 {{c|true}}。}} | ||
− | |||
− | |||
− | |||
===返回值=== | ===返回值=== |
2025年1月13日 (一) 00:43的最后版本
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
[编辑] 参阅
返回完整匹配结尾和目标序列结尾之间的子序列 (公开成员函数) |