std::sub_match::operator string_type, std::sub_match::str - cppreference.com (original) (raw)

| operator string_type() const; | (1) | | | ------------------------------ | --- | | | string_type str() const; | (2) | |

Converts to an object of the underlying std::basic_string type.

  1. An implicit conversion.

  2. An explicit conversion.

[edit] Return value

The matched character sequence as an object of the underlying std::basic_string type. If the matched member is false, then returns the empty string.

[edit] Complexity

Linear in the length of the underlying character sequence.

[edit] Example

#include #include #include #include   int main() { const std::string html{R"(")"}; 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'; } }

Output:

https://cppreference.com https cppreference com