Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |regex‎ |sub match
       
       
       
      Regular expressions library
      Classes
      (C++11)
      Algorithms
      Iterators
      Exceptions
      Traits
      Constants
      (C++11)
      Regex Grammar
       
      std::sub_match
      Member functions
      sub_match::strsub_match::operator string_type
      Non-member functions
      (until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
       
      operator string_type()const;
      (1)
      string_type str()const;
      (2)

      Converts to an object of the underlyingstd::basic_string type.

      1) An implicit conversion.
      2) An explicit conversion.

      [edit]Return value

      The matched character sequence as an object of the underlyingstd::basic_string type. If thematched member isfalse, then returns the empty string.

      [edit]Complexity

      Linear in the length of the underlying character sequence.

      [edit]Example

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

      Output:

      https://cppreference.comhttpscppreferencecom
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/regex/sub_match/str&oldid=178367"

      [8]ページ先頭

      ©2009-2025 Movatter.jp