名稱空間
變體
操作

std::sub_match<BidirIt>::operator string_type, std::sub_match<BidirIt>::str

來自 cppreference.com
< cpp‎ | regex‎ | sub_match
 
 
 
正則表示式庫
(C++11)
演算法
迭代器
異常
特性
常量
(C++11)
正則表示式語法
 
std::sub_match
成員函式
sub_match::strsub_match::operator string_type
非成員函式
(直到 C++20)(直到 C++20)(直到 C++20)(直到 C++20)(直到 C++20)(C++20 起)
 
operator string_type() const;
(1)
string_type str() const;
(2)

轉換為底層 std::basic_string 型別的物件。

1) 隱式轉換。
2) 顯式轉換。

[編輯] 返回值

作為底層 std::basic_string 型別的物件的匹配字元序列。如果 matched 成員為 false,則返回空字串。

[編輯] 複雜度

與底層字元序列的長度呈線性關係。

[編輯] 示例

#include <cassert>
#include <iostream>
#include <regex>
#include <string>
 
int main()
{
    const std::string html{R"("<a href="https://cppreference.tw/">)"};
    const std::regex re{"(http|https|ftp)://([a-z]+)\\.([a-z]{3})"};
    std::smatch parts;
    std::regex_search(html, parts, re);
    for (std::ssub_match const& sub : parts)
    {
        const std::string s = sub; // (1) implicit conversion
        assert(s == sub.str());    // (2)
        std::cout << s << '\n';
    }
}

輸出

https://cppreference.tw
https
cppreference
com