basic_regex_constants — basic_regex 상수
basic_regex_constants — basic_regex 상수
std::basic_regex는 정규식 문법 옵션을 나타내는 상수 멤버들을 제공해요. std::regex_constants의 상수에 대응해요.
<regex> 헤더에 있어요.
출처: cppreference
본문
// <regex> 헤더
static constexpr std::regex_constants::syntax_option_type icase =
std::regex_constants::icase;
static constexpr std::regex_constants::syntax_option_type nosubs =
std::regex_constants::nosubs;
static constexpr std::regex_constants::syntax_option_type optimize =
std::regex_constants::optimize;
// ... 그 외 문법 옵션들
이 상수들은 정규식 객체(std::basic_regex) 생성 시 문법 옵션으로 쓰여요.
주요 옵션
| 옵션 | 설명 |
|---|---|
icase |
대소문자 무시 |
nosubs |
부분 일치(sub-match)를 만들지 않음 |
optimize |
매칭 최적화 (구성 비용 증가) |
collate |
로케일 정렬 규칙 적용 |
#include <regex>
// 접근 예
std::regex::icase; // 멤버 상수
std::regex_constants::icase; // 네임스페이스 상수
// 사용
std::regex re("hello", std::regex::icase); // 대소문자 무시
if (std::regex_search("HELLO", re)) {
// 매치됨
}
이 상수들은 옵션을 조합해 쓸 수 있어요.
std::regex re("a+", std::regex::icase | std::regex::optimize);
std::basic_regex 멤버 상수는 std::regex_constants의 값과 동일해서, 정규식을 만들 때 문법 동작을 제어하는 데 사용돼요.