다음을 통해 공유


basic_regex 클래스

정규식을 래핑합니다.

구문

template <class Elem, class RXtraits>
class basic_regex

매개 변수

Elem
일치 항목을 찾을 요소의 형식입니다.

RXtraits
요소에 대한 특성 클래스입니다.

설명

클래스 템플릿은 정규식을 보유하는 개체를 설명합니다. 이 클래스 템플릿의 개체는 regex_match, regex_searchregex_replace 템플릿 함수에 전달할 수 있습니다. 또한 정규식과 일치하는 텍스트를 검색하기 위해 적합한 텍스트 문자열 인수를 전달합니다. 이 클래스 템플릿에는 형식 요소에 대한 형식 정의 regex와 형식 char요소에 대한 wregex사용하는 두 가지 특수화가 있습니다wchar_t.

템플릿 인수 RXtraits 는 클래스 템플릿이 지원하는 정규식 구문의 다양한 중요한 속성을 설명합니다. 이러한 정규식 특성을 지정하는 클래스는 regex_traits 클래스 형식의 개체와 동일한 외부 인터페이스를 가져야 합니다.

일부 함수는 정규식을 정의하는 피연산자 시퀀스를 사용합니다. 그러한 피연산자 시퀀스를 여러 방법으로 지정할 수 있습니다.

ptr: null로 끝나는 시퀀스(예: 형식의 Elem에 대한 C 문자열)ptr가 null 포인터가 아니어야 합니다. 여기서 종료 요소는 값 value_type() 이며 피연산자 시퀀스의 일부가 아닙니다.char

ptr, count: 시작 ptr 요소 시 count 퀀스(null 포인터가 아니어야 합니다)입니다.

str: 개체에서 지정한 basic_string 시퀀스입니다. str

first, last: 반복기로 구분된 요소 시퀀스 및 last범위 내의 요소 시퀀스 first 입니다.[first, last)

rightbasic_regex: 개체right

위의 멤버 함수는 RXtraits 형식에서 설명하는 옵션 외에도 정규식 해석에 대한 다양한 옵션을 지정하는 인수 flags 사용합니다.

멤버

멤버 기본값
public static const flag_type icase regex_constants::icase
public static const flag_type nosubs regex_constants::nosubs
public static const flag_type 최적화 regex_constants::optimize
public static const flag_type 데이터 정렬 regex_constants::collate
public static const flag_type ECMAScript regex_constants::ECMAScript
public static const flag_type basic regex_constants::basic
public static const flag_type 확장 regex_constants::extended
public static const flag_type awk regex_constants::awk
public static const flag_type grep regex_constants::grep
public static const flag_type egrep regex_constants::egrep
프라이빗 RXtraits 특성

생성자

생성자 Description
basic_regex Regular Expression 개체를 생성합니다.

Typedef

형식 이름 설명
flag_type 구문 옵션 플래그의 형식입니다.
locale_type 저장된 로캘 개체의 형식입니다.
value_type 요소 형식입니다.

멤버 함수

멤버 함수 설명
assign 정규식 개체에 값을 할당합니다.
flags 구문 옵션 플래그를 반환합니다.
getloc 저장된 로캘 개체를 반환합니다.
imbue 저장된 로캘 개체를 변경합니다.
mark_count 일치하는 하위 식의 수를 반환합니다.
swap 두 정규식 개체를 바꿉니다.

연산자

연산자 설명
operator= 정규식 개체에 값을 할당합니다.

요구 사항

헤더:<regex>

네임스페이스: std

예시

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

using namespace std;

int main()
{
    regex::value_type elem = 'x';
    regex::flag_type flag = regex::grep;

    elem = elem;  // to quiet "unused" warnings
    flag = flag;

    // constructors
    regex rx0;
    cout << "match(\"abc\", \"\") == " << boolalpha
        << regex_match("abc", rx0) << endl;

    regex rx1("abcd", regex::ECMAScript);
    cout << "match(\"abc\", \"abcd\") == " << boolalpha
        << regex_match("abc", rx1) << endl;

    regex rx2("abcd", 3);
    cout << "match(\"abc\", \"abc\") == " << boolalpha
        << regex_match("abc", rx2) << endl;

    regex rx3(rx2);
    cout << "match(\"abc\", \"abc\") == " << boolalpha
        << regex_match("abc", rx3) << endl;

    string str("abcd");
    regex rx4(str);
    cout << "match(string(\"abcd\"), \"abc\") == " << boolalpha
        << regex_match("abc", rx4) << endl;

    regex rx5(str.begin(), str.end() - 1);
    cout << "match(string(\"abc\"), \"abc\") == " << boolalpha
        << regex_match("abc", rx5) << endl;
    cout << endl;

    // assignments
    rx0 = "abc";
    rx0 = rx1;
    rx0 = str;

    rx0.assign("abcd", regex::ECMAScript);
    rx0.assign("abcd", 3);
    rx0.assign(rx1);
    rx0.assign(str);
    rx0.assign(str.begin(), str.end() - 1);

    rx0.swap(rx1);

    // mark_count
    cout << "\"abc\" mark_count == "
        << regex("abc").mark_count() << endl;
    cout << "\"(abc)\" mark_count == "
        << regex("(abc)").mark_count() << endl;

    // locales
    regex::locale_type loc = rx0.imbue(locale());
    cout << "getloc == imbued == " << boolalpha
        << (loc == rx0.getloc()) << endl;

    // initializer_list
    regex rx6({ 'a', 'b', 'c' }, regex::ECMAScript);
    cout << "match(\"abc\") == " << boolalpha
        << regex_match("abc", rx6);
    cout << endl;
}
match("abc", "") == false
match("abc", "abcd") == false
match("abc", "abc") == true
match("abc", "abc") == true
match(string("abcd"), "abc") == false
match(string("abc"), "abc") == true

"abc" mark_count == 0
"(abc)" mark_count == 1
getloc == imbued == true
match("abc") == true

basic_regex::assign

정규식 개체에 값을 할당합니다.

basic_regex& assign(
    const basic_regex& right);

basic_regex& assign(
    const Elem* ptr,
    flag_type flags = ECMAScript);

basic_regex& assign(
    const Elem* ptr,
    size_type len,
    flag_type flags = ECMAScript);

basic_regex& assign(
    initializer_list<_Elem> IList,
    flag_type flags = regex_constants::ECMAScript);

template <class STtraits, class STalloc>
basic_regex& assign(
    const basic_string<Elem, STtraits, STalloc>& str,
    flag_type flags = ECMAScript);

template <class InIt>
basic_regex& assign(
    InIt first, InIt last,
    flag_type flags = ECMAScript);

매개 변수

STtraits
문자열 소스에 대한 특성 클래스입니다.

STalloc
문자열 소스에 대한 할당자 클래스입니다.

Init
범위 소스에 대한 입력 반복기 형식입니다.

right
복사할 Regex 소스입니다.

ptr
복사할 시퀀스의 시작에 대한 포인터입니다.

flags
복사하는 동안 추가할 구문 옵션 플래그입니다.

len/TD>
복사할 시퀀스의 길이입니다.

str
복사할 문자열입니다.

first
복사할 시퀀스의 시작입니다.

last
복사할 시퀀스의 끝입니다.

IList
복사할 initializer_list입니다.

설명

각 멤버 함수는 *this에 보유된 정규식을 피연산자 시퀀스에 설명된 정규식으로 대체한 후 *this를 반환합니다.

basic_regex::basic_regex

Regular Expression 개체를 생성합니다.

basic_regex();

explicit basic_regex(
    const Elem* ptr,
    flag_type flags);

explicit basic_regex(
    const Elem* ptr,
    size_type len,
    flag_type flags);

basic_regex(
    const basic_regex& right);

basic_regex(
    initializer_list<Type> IList,
    flag_type flags);

template <class STtraits, class STalloc>
explicit basic_regex(
    const basic_string<Elem, STtraits, STalloc>& str,
    flag_type flags);

template <class InIt>
explicit basic_regex(
    InIt first,
    InIt last,
    flag_type flags);

매개 변수

STtraits
문자열 소스에 대한 특성 클래스입니다.

STalloc
문자열 소스에 대한 할당자 클래스입니다.

Init
범위 소스에 대한 입력 반복기 형식입니다.

right
복사할 Regex 소스입니다.

ptr
복사할 시퀀스의 시작에 대한 포인터입니다.

flags
복사하는 동안 추가할 구문 옵션 플래그입니다.

len/TD>
복사할 시퀀스의 길이입니다.

str
복사할 문자열입니다.

first
복사할 시퀀스의 시작입니다.

last
복사할 시퀀스의 끝입니다.

IList
복사할 initializer_list입니다.

설명

모든 생성자가 RXtraits 형식의 기본 생성된 개체를 저장합니다.

첫 번째 생성자는 빈 basic_regex 개체를 생성합니다. 다른 생성자는 피연산자 시퀀스에서 설명하는 정규식을 보유하는 basic_regex 개체를 생성합니다.

basic_regex 개체는 regex_match, regex_search 또는 regex_replace 전달될 때 문자 시퀀스와 일치하지 않습니다.

basic_regex::flag_type

구문 옵션 플래그의 형식입니다.

typedef regex_constants::syntax_option_type flag_type;

설명

이 형식은 regex_constants::syntax_option_type의 동의어입니다.

basic_regex::flags

구문 옵션 플래그를 반환합니다.

flag_type flags() const;

설명

멤버 함수는 basic_regex::assign 멤버 함수 중 하나에 대한 최근 호출에 전달된 flag_type 인수의 값을 반환하거나, 이러한 호출이 수행되지 않은 경우 생성자에 전달된 값을 반환합니다.

basic_regex::getloc

저장된 로캘 개체를 반환합니다.

locale_type getloc() const;

설명

멤버 함수는 traits.regex_traits::getloc()을 반환합니다.

basic_regex::imbue

저장된 로캘 개체를 변경합니다.

locale_type imbue(locale_type loc);

매개 변수

Loc
저장할 로캘 개체입니다.

설명

멤버 함수는 *this를 비우고 traits.regex_traits::imbue(loc)를 반환합니다.

basic_regex::locale_type

저장된 로캘 개체의 형식입니다.

typedef typename RXtraits::locale_type locale_type;

설명

이 형식은 regex_traits::locale_type의 동의어입니다.

basic_regex::mark_count

일치하는 하위 식의 수를 반환합니다.

unsigned mark_count() const;

설명

멤버 함수는 정규식의 캡처 그룹 수를 반환합니다.

basic_regex::operator=

정규식 개체에 값을 할당합니다.

basic_regex& operator=(const basic_regex& right);

basic_regex& operator=(const Elem *str);

template <class STtraits, class STalloc>
basic_regex& operator=(const basic_string<Elem, STtraits, STalloc>& str);

매개 변수

STtraits
문자열 소스에 대한 특성 클래스입니다.

STalloc
문자열 소스에 대한 할당자 클래스입니다.

right
복사할 Regex 소스입니다.

str
복사할 문자열입니다.

설명

각 연산자는 *this 에 보유된 정규식을 피연산자 시퀀스에 설명된 정규식으로 대체한 후 *this를 반환합니다.

basic_regex::swap

두 정규식 개체를 바꿉니다.

void swap(basic_regex& right) throw();

매개 변수

right
바꾸려는 정규식 개체입니다.

설명

멤버 함수는 정규식을 오른쪽오른쪽으로 *this 바꿉니다. 일정한 시간에 이 작업을 수행하고 예외를 throw하지 않습니다.

basic_regex::value_type

요소 형식입니다.

typedef Elem value_type;

설명

형식은 템플릿 매개 변수 Elem의 동의어입니다.

참고 항목

<regex>
regex_match
regex_search
regex_replace
regex
wregex
regex_traits 클래스