다음을 통해 공유


match_results 클래스

부분 일치 시퀀스를 보유합니다.

구문

template <class BidIt, class Alloc>
class match_results

매개 변수

BidIt
부분 일치에 대한 반복기 형식입니다.

Alloc
스토리지 관리를 위한 할당자의 형식입니다.

설명

클래스 템플릿은 정규식 검색에 의해 생성된 형식 sub_match<BidIt> 요소의 수정할 수 없는 시퀀스를 제어하는 개체를 설명합니다. 각 요소는 해당 요소에 해당하는 캡처 그룹과 일치하는 하위 시퀀스를 가리킵니다.

생성자

생성자 Description
match_results 개체를 생성합니다.

Typedef

형식 이름 설명
allocator_type 스토리지 관리를 위한 할당자의 형식입니다.
char_type 요소의 형식입니다.
const_iterator 부분 일치에 대한 상수 반복기 형식입니다.
const_reference 요소 const 참조의 형식입니다.
difference_type 반복기 차이의 형식입니다.
iterator 부분 일치에 대한 반복기 형식입니다.
reference 요소 참조의 형식입니다.
size_type 부분 일치 수의 형식입니다.
string_type 문자열의 형식입니다.
value_type 부분 일치의 형식입니다.

멤버 함수

멤버 함수 설명
begin 부분 일치 시퀀스의 시작을 지정합니다.
empty 부분 일치가 없는지 테스트합니다.
end 부분 일치 시퀀스의 끝을 지정합니다.
format 부분 일치의 서식을 지정합니다.
get_allocator 저장된 할당자를 반환합니다.
length 부분 일치의 길이를 반환합니다.
max_size 부분 일치의 최대 수를 가져옵니다.
위치 하위 그룹의 시작 오프셋을 가져옵니다.
prefix 첫 번째 부분 일치 전의 시퀀스를 가져옵니다.
size 부분 일치 수를 계산합니다.
str 부분 일치 항목을 반환합니다.
접미사 마지막 부분 일치 후 시퀀스를 가져옵니다.
swap 두 match_results 개체를 바꿉니다.

연산자

연산자 설명
operator= match_results 개체를 복사합니다.
operator[] 하위 개체에 액세스합니다.

요구 사항

헤더:<regex>

네임스페이스: std

예시

// std__regex__match_results.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>

int main()
{
    std::regex rx("c(a*)|(b)");
    std::cmatch mr;

    std::regex_search("xcaaay", mr, rx);

    std::cout << "prefix: matched == " << std::boolalpha
        << mr.prefix().matched
        << ", value == " << mr.prefix() << std::endl;
    std::cout << "whole match: " << mr.length() << " chars, value == "
        << mr.str() << std::endl;
    std::cout << "suffix: matched == " << std::boolalpha
        << mr.suffix().matched
        << ", value == " << mr.suffix() << std::endl;
    std::cout << std::endl;

    std::string fmt("\"c(a*)|(b)\" matched \"$&\"\n"
        "\"(a*)\" matched \"$1\"\n"
        "\"(b)\" matched \"$2\"\n");
    std::cout << mr.format(fmt) << std::endl;
    std::cout << std::endl;

    // index through submatches
    for (size_t n = 0; n < mr.size(); ++n)
    {
        std::cout << "submatch[" << n << "]: matched == " << std::boolalpha
            << mr[n].matched <<
            " at position " << mr.position(n) << std::endl;
        std::cout << "  " << mr.length(n)
            << " chars, value == " << mr[n] << std::endl;
    }
    std::cout << std::endl;

    // iterate through submatches
    for (std::cmatch::iterator it = mr.begin(); it != mr.end(); ++it)
    {
        std::cout << "next submatch: matched == " << std::boolalpha
            << it->matched << std::endl;
        std::cout << "  " << it->length()
            << " chars, value == " << *it << std::endl;
    }
    std::cout << std::endl;

    // other members
    std::cout << "empty == " << std::boolalpha << mr.empty() << std::endl;

    std::cmatch::allocator_type al = mr.get_allocator();
    std::cmatch::string_type str = std::string("x");
    std::cmatch::size_type maxsiz = mr.max_size();
    std::cmatch::char_type ch = 'x';
    std::cmatch::difference_type dif = mr.begin() - mr.end();
    std::cmatch::const_iterator cit = mr.begin();
    std::cmatch::value_type val = *cit;
    std::cmatch::const_reference cref = val;
    std::cmatch::reference ref = val;

    maxsiz = maxsiz;  // to quiet "unused" warnings
    if (ref == cref)
        ch = ch;
    dif = dif;

    return (0);
}
prefix: matched == true, value == x
whole match: 4 chars, value == caaa
suffix: matched == true, value == y

"c(a*)|(b)" matched "caaa"
"(a*)" matched "aaa"
"(b)" matched ""

submatch[0]: matched == true at position 1
  4 chars, value == caaa
submatch[1]: matched == true at position 2
  3 chars, value == aaa
submatch[2]: matched == false at position 6
  0 chars, value ==

next submatch: matched == true
  4 chars, value == caaa
next submatch: matched == true
  3 chars, value == aaa
next submatch: matched == false
  0 chars, value ==

empty == false

match_results::allocator_type

스토리지 관리를 위한 할당자의 형식입니다.

typedef Alloc allocator_type;

설명

typedef는 템플릿 인수 Alloc의 동의어입니다.

match_results::begin

부분 일치 시퀀스의 시작을 지정합니다.

const_iterator begin() const;

설명

멤버 함수는 시퀀스의 첫 번째 요소(또는 빈 시퀀스의 끝 바로 다음)를 가리키는 임의 액세스 반복기를 반환합니다.

match_results::char_type

요소의 형식입니다.

typedef typename iterator_traits<BidIt>::value_type char_type;

설명

typedef는 iterator_traits<BidIt>::value_type형식의 동의어로, 검색된 문자 시퀀스의 요소 형식입니다.

match_results::const_iterator

부분 일치에 대한 상수 반복기 형식입니다.

typedef T0 const_iterator;

설명

typedef는 제어되는 시퀀스의 상수 임의 액세스 반복기로 사용될 수 있는 개체를 설명합니다.

match_results::const_reference

요소 const 참조의 형식입니다.

typedef const typename Alloc::const_reference const_reference;

설명

typedef는 제어되는 시퀀스의 요소에 대한 상수 참조로 사용될 수 있는 개체를 설명합니다.

match_results::d ifference_type

반복기 차이의 형식입니다.

typedef typename iterator_traits<BidIt>::difference_type difference_type;

설명

typedef는 iterator_traits<BidIt>::difference_type형식의 동의어이며, 제어되는 시퀀스의 요소를 가리키는 두 반복기 사이의 차이를 나타낼 수 있는 개체에 대해 설명합니다.

match_results::empty

부분 일치가 없는지 테스트합니다.

bool empty() const;

설명

멤버 함수는 정규식 검색에 실패한 경우에만 true를 반환합니다.

match_results::end

부분 일치 시퀀스의 끝을 지정합니다.

const_iterator end() const;

설명

멤버 함수는 시퀀스 끝의 바로 다음을 가리키는 반복기를 반환합니다.

match_results::format

부분 일치의 서식을 지정합니다.

template <class OutIt>
OutIt format(OutIt out,
    const string_type& fmt, match_flag_type flags = format_default) const;

string_type format(const string_type& fmt, match_flag_type flags = format_default) const;

매개 변수

OutIt
출력 반복기 형식입니다.

out
쓸 출력 스트림입니다.

Fmt
서식 문자열입니다.

flags
서식 플래그입니다.

설명

각 멤버 함수는 fmt 형식의 컨트롤 아래에 서식 이 지정된 텍스트를 생성합니다. 첫 번째 멤버 함수는 인수 로 정의된 시퀀스에 서식이 지정된 텍스트를 쓰고 반환합니다. 두 번째 멤버 함수는 서식이 지정된 텍스트의 복사본을 포함하는 문자열 개체를 반환합니다.

서식 있는 텍스트를 생성하려면 서식 문자열의 리터럴 텍스트를 일반적으로 대상 시퀀스로 복사합니다. 서식 문자열의 각 이스케이프 시퀀스가 대표 텍스트로 대체됩니다. 복사 및 교체 정보는 함수에 전달된 서식 플래그에서 제어합니다.

match_results::get_allocator

저장된 할당자를 반환합니다.

allocator_type get_allocator() const;

설명

멤버 함수는 *this에서 사용된 할당자 개체의 복사본을 반환하여 해당 sub_match 개체를 할당합니다.

match_results::iterator

부분 일치에 대한 반복기 형식입니다.

typedef const_iterator iterator;

설명

이 형식은 제어되는 시퀀스의 임의 액세스 반복기로 사용될 수 있는 개체를 설명합니다.

match_results::length

부분 일치의 길이를 반환합니다.

difference_type length(size_type sub = 0) const;

매개 변수

sub
부분 일치 항목의 인덱스입니다.

설명

멤버 함수는 (*this)[sub].length()를 반환합니다.

match_results::match_results

개체를 생성합니다.

explicit match_results(const Alloc& alloc = Alloc());

match_results(const match_results& right);

매개 변수

Alloc
저장할 할당자 개체입니다.

right
복사할 match_results 개체입니다.

설명

첫 번째 생성자는 부분 일치 항목을 보유하지 않는 match_results 개체를 구성합니다. 두 번째 생성자는 오른쪽 복사본match_results 개체를 생성합니다.

match_results::max_size

부분 일치의 최대 수를 가져옵니다.

size_type max_size() const;

설명

멤버 함수는 개체가 제어할 수 있는 가장 긴 시퀀스의 길이를 반환합니다.

match_results::operator=

match_results 개체를 복사합니다.

match_results& operator=(const match_results& right);

매개 변수

right
복사할 match_results 개체입니다.

설명

멤버 연산자는 제어되는 *this 시퀀스를 오른쪽으로 제어되는 시퀀스의 복사본으로 바꿉니다.

match_results::operator[]

하위 개체에 액세스합니다.

const_reference operator[](size_type n) const;

매개 변수

n
부분 일치 항목의 인덱스입니다.

설명

멤버 함수는 제어되는 시퀀스의 요소 n에 대한 참조를 반환하거나 캡처 그룹 n이 일치 항목의 일부가 아닌 경우 size() <= nsub_match 개체에 대한 참조를 반환합니다.

match_results::p osition

하위 그룹의 시작 오프셋을 가져옵니다.

difference_type position(size_type sub = 0) const;

매개 변수

sub
부분 일치 항목의 인덱스입니다.

설명

멤버 함수는 std::distance(prefix().first, (*this)[sub].first), 즉 대상 시퀀스의 첫 번째 문자부터 제어되는 시퀀스의 n 요소가 가리키는 부분 일치의 첫 번째 문자까지 거리를 반환합니다.

match_results::p refix

첫 번째 부분 일치 전의 시퀀스를 가져옵니다.

const_reference prefix() const;

설명

멤버 함수는 대상 시퀀스의 시작에서 시작되고 sub_match<BidIt> 에서 끝나는 문자 시퀀스 즉, 일치하는 하위 시퀀스 앞에 오는 텍스트를 가리키는 (*this)[0].first형식의 개체에 대한 참조를 반환합니다.

match_results::reference

요소 참조의 형식입니다.

typedef const_reference reference;

설명

이 형식은 const_reference형식의 동의어입니다.

match_results::size

부분 일치 수를 계산합니다.

size_type size() const;

설명

멤버 함수는 검색에 사용된 정규식에서 캡처 그룹 수보다 1이 큰 수를 반환하고, 검색되지 않은 경우 0을 반환합니다.

match_results::size_type

부분 일치 수의 형식입니다.

typedef typename Alloc::size_type size_type;

설명

이 형식은 Alloc::size_type형식의 동의어입니다.

match_results::str

부분 일치 항목을 반환합니다.

string_type str(size_type sub = 0) const;

매개 변수

sub
부분 일치 항목의 인덱스입니다.

설명

멤버 함수는 string_type((*this)[sub])를 반환합니다.

match_results::string_type

문자열의 형식입니다.

typedef basic_string<char_type> string_type;

설명

이 형식은 basic_string<char_type>형식의 동의어입니다.

match_results::suffix

마지막 부분 일치 후 시퀀스를 가져옵니다.

const_reference suffix() const;

설명

멤버 함수는 sub_match<BidIt> 에서 시작되고 대상 시퀀스의 끝에서 끝나는 문자 시퀀스 즉, 일치하는 하위 시퀀스 뒤에 오는 텍스트를 가리키는 (*this)[size() - 1].second 형식의 개체에 대한 참조를 반환합니다.

match_results::swap

두 match_results 개체를 바꿉니다.

void swap(const match_results& right) throw();

매개 변수

right
바꾸려는 match_results 개체입니다.

설명

멤버 함수는 상수 시간에 적절한 내용과 내용을 *this 교환하며 예외를 throw하지 않습니다.

match_results::value_type

부분 일치의 형식입니다.

typedef sub_match<BidIt> value_type;

설명

typedef는 sub_match<BidIt>형식의 동의어입니다.

참고 항목

<regex>