std::sub_match<BidirIt>:: operator string_type, std::sub_match<BidirIt>:: str
From ja.cppreference.net
|
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.net/">)"}; 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) 暗黙的変換 assert(s == sub.str()); // (2) std::cout << s << '\n'; } }
出力:
https://ja.cppreference.net https cppreference com