Namespaces
Variants

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

From cppreference.net
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
Exceptions
Traits
Constants
(C++11)
Regex Grammar
std::sub_match
Member functions
sub_match::str sub_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)

기본 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://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://cppreference.net
https
cppreference
com