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> |
[編輯] 成員函式
構造物件 (public member function) | |
析構物件 (public member function) | |
賦值內容 (public member function) | |
返回關聯的分配器 (public member function) | |
狀態 | |
檢查結果是否可用 (公開成員函式) | |
大小 | |
檢查匹配是否成功 (public member function) | |
在完全建立結果狀態時返回匹配的數量 (public member function) | |
返回子匹配的最大可能數量 (public member function) | |
元素訪問 | |
返回特定子匹配的長度 (public member function) | |
返回特定子匹配的第一個字元的位置 (public member function) | |
返回特定子匹配的字元序列 (public member function) | |
返回指定的子匹配 (public member function) | |
返回目標序列開頭與完整匹配開頭之間的子序列 (public member function) | |
返回完整匹配結束與目標序列結束之間的子序列 (public member function) | |
迭代器 | |
返回子匹配列表開頭的迭代器 (public member function) | |
返回子匹配列表末尾的迭代器 (public member function) | |
格式 | |
格式化匹配結果以供輸出 (public member function) | |
修改器 | |
交換內容 (public member function) |
[編輯] 非成員函式
(在 C++20 中移除) |
按字典順序比較兩個匹配結果中的值 (函式模板) |
特化 std::swap 演算法 (函式模板) |