Namespaces
Variants

std::regex_constants:: error_type

From cppreference.net
헤더에 정의됨 <regex>
using error_type = /* implementation-defined */ ;
(1) (C++11부터)
constexpr error_type error_collate = /* unspecified */ ;

constexpr error_type error_ctype = /* unspecified */ ;
constexpr error_type error_escape = /* unspecified */ ;
constexpr error_type error_backref = /* unspecified */ ;
constexpr error_type error_brack = /* unspecified */ ;
constexpr error_type error_paren = /* unspecified */ ;
constexpr error_type error_brace = /* unspecified */ ;
constexpr error_type error_badbrace = /* unspecified */ ;
constexpr error_type error_range = /* unspecified */ ;
constexpr error_type error_space = /* unspecified */ ;
constexpr error_type error_badrepeat = /* unspecified */ ;
constexpr error_type error_complexity = /* unspecified */ ;

constexpr error_type error_stack = /* unspecified */ ;
(2) (C++11부터)
(C++17부터 inline)
1) error_type 는 정규식 파싱 중 발생할 수 있는 오류를 설명하는 타입입니다.

목차

상수

이름 설명
error_collate 표현식에 유효하지 않은 콜레이션 요소 이름이 포함됨
error_ctype 표현식에 유효하지 않은 문자 클래스 이름이 포함됨
error_escape 표현식에 유효하지 않은 이스케이프 문자 또는 후행 이스케이프가 포함됨
error_backref 표현식에 유효하지 않은 역참조가 포함됨
error_brack 표현식에 짝이 맞지 않는 대괄호 ( '[' ']' )가 포함됨
error_paren 표현식에 짝이 맞지 않는 괄호 ( '(' ')' )가 포함됨
error_brace 표현식에 짝이 맞지 않는 중괄호 ( '{' '}' )가 포함됨
error_badbrace 표현식에 { } 표현식 내 유효하지 않은 범위가 포함됨
error_range 표현식에 유효하지 않은 문자 범위가 포함됨 (예: [b-a])
error_space 표현식을 유한 상태 머신으로 변환하기에 메모리가 부족함
error_badrepeat '*' , '?' , '+' 또는 '{' 앞에 유효한 정규 표현식이 없음
error_complexity 시도된 매칭의 복잡도가 사전 정의된 수준을 초과함
error_stack 매칭을 수행하기에 메모리가 부족함

예제

정규 표현식 검사기를 구현합니다:

#include <cstddef>
#include <iomanip>
#include <iostream>
#include <regex>
#include <sstream>
#include <string>
void regular_expression_checker(const std::string& text,
                                const std::string& regex,
                                const std::regex::flag_type flags)
{
    std::cout << "Text: " << std::quoted(text) << '\n'
              << "Regex: " << std::quoted(regex) << '\n';
    try
    {
        const std::regex re{regex, flags};
        const bool matched = std::regex_match(text, re);
        std::stringstream out;
        out << (matched ? "MATCH!\n" : "DOES NOT MATCH!\n");
        std::smatch m;
        if (std::regex_search(text, m, re); !m.empty())
        {
            out << "prefix = [" << m.prefix().str().data() << "]\n";
            for (std::size_t i{}; i != m.size(); ++i)
                out << "  m[" << i << "] = [" << m[i].str().data() << "]\n";
            out << "suffix = [" << m.suffix().str().data() << "]\n";
        }
        std::cout << out.str() << '\n';
    }
    catch (std::regex_error& e)
    {
        std::cout << "Error: " << e.what() << ".\n\n";
    }
}
int main()
{
    constexpr std::regex::flag_type your_flags
        = std::regex::flag_type{0}
    // 지원되는 문법 중 하나를 선택하세요:
        | std::regex::ECMAScript
    //  | std::regex::basic
    //  | std::regex::extended
    //  | std::regex::awk
    //  | std::regex::grep
    //  | std::regex::egrep
    // 다음 옵션들 중 아무거나 선택하세요:
    //  | std::regex::icase
    //  | std::regex::nosubs
    //  | std::regex::optimize
    //  | std::regex::collate
    //  | std::regex::multiline
        ;
    const std::string your_text = "Hello regular expressions.";
    const std::string your_regex = R"(([a-zA-Z]+) ([a-z]+) ([a-z]+)\.)";
    regular_expression_checker(your_text, your_regex, your_flags);
    regular_expression_checker("Invalid!", R"(((.)(.))", your_flags);
    regular_expression_checker("Invalid!", R"([.)", your_flags);
    regular_expression_checker("Invalid!", R"([.]{})", your_flags);
    regular_expression_checker("Invalid!", R"([1-0])", your_flags);
}

가능한 출력:

Text: "Hello regular expressions."
Regex: "([a-zA-Z]+) ([a-z]+) ([a-z]+)\\."
MATCH!
prefix = []
  m[0] = [Hello regular expressions.]
  m[1] = [Hello]
  m[2] = [regular]
  m[3] = [expressions]
suffix = []
Text: "Invalid!"
Regex: "((.)(.)"
Error: Mismatched '(' and ')' in regular expression.
Text: "Invalid!"
Regex: "[."
Error: Unexpected character within '[...]' in regular expression.
Text: "Invalid!"
Regex: "[.]{}"
Error: Invalid range in '{}' in regular expression.
Text: "Invalid!"
Regex: "[1-0]"
Error: Invalid range in bracket expression..

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 2053 C++11 상수들이 static 으로 선언됨 static 지정자를 제거함

참고 항목

정규 표현식 라이브러리에서 생성된 오류를 보고함
(클래스)