match_flag_type — std::regex_constants::match_flag_type

match_flag_type — std::regex_constants::match_flag_type

match_flag_typestd::regex_match, std::regex_search 같은 함수의 매칭 동작을 제어하는 플래그 타입이에요. C++11에서 도입됐어요. <regex> 헤더에 있어요.

std::regex_constants 네임스페이스에 있어요.

출처: cppreference

본문

// <regex> 헤더, C++11
using match_flag_type = /* implementation-defined */;   // (1)

constexpr match_flag_type match_default =     {};   // 기본 (0)
constexpr match_flag_type match_not_bol =     /* unspecified */;
constexpr match_flag_type match_not_eol =     /* unspecified */;
// ... 그 외 플래그

주요 플래그

플래그 설명
match_default 기본 동작 (0)
match_not_bol ^를 문자열 시작으로 취급하지 않음
match_not_eol $를 문자열 끝으로 취급하지 않음
match_not_bow \b를 단어 시작으로 취급하지 않음
match_not_eow \b를 단어 끝으로 취급하지 않음
match_any 가능하면 아무 매치나 허용
match_not_null 빈 매치 금지
match_continuous 시작 위치에만 매치
match_prev_avail 이전 문자가 존재함
match_not_bow, match_not_eow 단어 경계 제어

사용 예

#include <regex>
#include <iostream>

std::string s = "hello world";
std::regex re("world");
std::smatch m;

// 기본 매칭
std::regex_search(s, m, re);   // true

// match_not_bow 등으로 앵커 동작 제어
std::regex re2("^hello");
std::regex_search(s, m, re2);   // true (시작 매치)

// 전체 일치를 강제하는 regex_match
bool ok = std::regex_match("hello", std::regex("hello"));  // true

플래그를 조합해 정확한 매칭 정책을 지정할 수 있어요.

std::regex_search(s, m, re,
    std::regex_constants::match_not_bol |
    std::regex_constants::match_any);

match_flag_type은 정규식 매칭의 세부 동작(앵커 처리, 빈 매치, 연속 매치 등)을 제어하는 데 사용돼요.

더 알아보기 (Learn more)

cppreference