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_results
中所含的首个 std::sub_match(下标
0)始终表示 regex 所做的目标序列内的完整匹配,而后继的 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
中移除)
|
以字典序比较两个匹配结果的值 (函数模板) |
(C++11)
|
特化 std::swap
算法 (函数模板) |