std::sub_match<BidirIt>::operator string_type, std::sub_match<BidirIt>::str
From cppreference.com
| 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