std::match_results

出自cppreference.com
< cpp‎ | regex
 
 
正則表達式庫
(C++11)
match_results
(C++11)
演算法
迭代器
異常
特徵
常量
(C++11)
正則表達式文法
 
 
在標頭 <regex> 定義
template<

    class BidirIt,
    class Alloc = std::allocator<std::sub_match<BidirIt>>

> class match_results;
(1) (C++11 起)
namespace pmr {

    template <class BidirIt>
    using match_results = std::match_results<BidirIt,
                              std::pmr::polymorphic_allocator<
                                  std::sub_match<BidirIt>>>;

}
(2) (C++17 起)

類模板 std::match_results 保有表示正則表達式匹配結果的字元序列的彙集。

這是特殊的知分配器容器。它只能默認創建、從 std::regex_iterator 獲得,或通過 std::regex_searchstd::regex_match 修改。因為 std::match_results 保有一組 std::sub_match,它們每個都是一對指向匹配的原初字元序列中的迭代器,所以如果原初字元序列被銷毀,或指向它的迭代器因為其他原因失效,那麼檢驗 std::match_results 的行為未定義。

std::match_results 中所含的首個 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 演算法
(函數模板) [編輯]