std::match_results
定义于头文件 <regex> |
||
template< class BidirIt, |
(1) | (自 C++11 起) |
namespace pmr { template <class BidirIt> |
(2) | (自 C++17 起) |
类模板 std::match_results
保存表示正则表达式匹配结果的字符序列的集合。
这是一个专门的感知分配器的容器。它只能默认创建,从 std::regex_iterator 获取,或由 std::regex_search 或 std::regex_match 修改。由于 std::match_results
保存 std::sub_match,每个子匹配都是一对指向原始匹配字符序列的迭代器,因此如果原始字符序列被销毁或指向它的迭代器因其他原因而失效,则检查 std::match_results
是未定义行为。
std::match_result
中包含的第一个 std::sub_match(索引 0)始终表示正则表达式在目标序列中进行的完整匹配,随后的 std::sub_match 表示子表达式匹配,其顺序与正则表达式中分隔子表达式的左括号相对应。
std::match_results
满足 AllocatorAwareContainer 和 SequenceContainer 的要求,但仅支持复制赋值、移动赋值以及为常量容器定义的操作,并且比较函数的语义与容器所需的不同。
内容 |
[编辑] 类型要求
-BidirIt 必须满足 LegacyBidirectionalIterator 的要求。 | ||
-Alloc 必须满足 Allocator 的要求。 |
[编辑] 特化
为常见字符序列类型提供了几种特化
定义于头文件
<regex> | |
类型 | 定义 |
std::cmatch
|
std::match_results<const char*> |
std::wcmatch
|
std::match_results<const wchar_t*> |
std::smatch
|
std::match_results<std::string::const_iterator> |
std::wsmatch
|
std::match_results<std::wstring::const_iterator> |
std::pmr::cmatch (C++17) |
std::pmr::match_results<const char*> |
std::pmr::wcmatch (C++17) |
std::pmr::match_results<const wchar_t*> |
std::pmr::smatch (C++17) |
std::pmr::match_results<std::string::const_iterator> |
std::pmr::wsmatch (C++17) |
std::pmr::match_results<std::wstring::const_iterator> |
[编辑] 成员类型
成员类型 | 定义 |
allocator_type
|
Allocator
|
value_type
|
std::sub_match<BidirIt> |
const_reference
|
const value_type& |
reference
|
value_type&
|
const_iterator
|
实现定义 (取决于底层容器) |
iterator
|
const_iterator
|
difference_type
|
std::iterator_traits<BidirIt>::difference_type |
size_type
|
std::allocator_traits<Alloc>::size_type |
char_type
|
std::iterator_traits<BidirIt>::value_type |
string_type
|
std::basic_string<char_type> |
[编辑] 成员函数
构造对象 (公有成员函数) | |
析构对象 (公有成员函数) | |
赋值内容 (公有成员函数) | |
返回关联的分配器 (公有成员函数) | |
状态 | |
检查结果是否可用 (公有成员函数) | |
大小 | |
检查匹配是否成功 (公有成员函数) | |
返回完全建立的结果状态中的匹配数 (公有成员函数) | |
返回子匹配的最大可能数量 (公有成员函数) | |
元素访问 | |
返回特定子匹配的长度 (公有成员函数) | |
返回特定子匹配的第一个字符的位置 (公有成员函数) | |
返回特定子匹配的字符序列 (公有成员函数) | |
返回指定的子匹配 (公有成员函数) | |
返回目标序列的开头和完整匹配的开头之间的子序列 (公有成员函数) | |
返回完整匹配的结尾和目标序列的结尾之间的子序列 (公有成员函数) | |
迭代器 | |
返回指向子匹配列表开头的迭代器 (公有成员函数) | |
返回指向子匹配列表结尾的迭代器 (公有成员函数) | |
格式化 | |
格式化匹配结果以进行输出 (公有成员函数) | |
修改器 | |
交换内容 (公有成员函数) |
[编辑] 非成员函数
(在 C++20 中移除) |
按字典序比较两个匹配结果中的值 (函数模板) |
特化 std::swap 算法 (函数模板) |