名前空間
変種
操作

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

From cppreference.com
< cpp‎ | regex‎ | sub match
 
 
 
正規表現ライブラリ
クラス
(C++11)
アルゴリズム
イテレータ
例外
Traits
定数
(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://ja.cppreference.dev/">)"};
    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://ja.cppreference.dev
https
cppreference
com
English 日本語 中文(简体) 中文(繁體)