std::basic_regex 常量

来自cppreference.com
< cpp‎ | regex‎ | basic regex
在标头 <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;
static constexpr std::regex_constants::syntax_option_type collate =
    std::regex_constants::collate;
static constexpr std::regex_constants::syntax_option_type ECMAScript =
    std::regex_constants::ECMAScript;
static constexpr std::regex_constants::syntax_option_type basic =
    std::regex_constants::basic;
static constexpr std::regex_constants::syntax_option_type extended =
    std::regex_constants::extended;
static constexpr std::regex_constants::syntax_option_type awk =
    std::regex_constants::awk;
static constexpr std::regex_constants::syntax_option_type grep =
    std::regex_constants::grep;
static constexpr std::regex_constants::syntax_option_type egrep =

    std::regex_constants::egrep;
(C++17 起)

std::basic_regex 定义了数个掌控通用正则表达式匹配语法的常量。

这些常量是 std::regex_constants 的重复:

文法选项 效果
ECMAScript 使用有改动的 ECMAScript 正则表达式文法
basic 使用基本 POSIX 正则表达式文法(文法文档)。
extended 使用扩展 POSIX 正则表达式文法(文法文档)。
awk 使用 POSIX 中 awk 工具所用的正则表达式文法(文法文档)。
grep 使用 POSIX 中 grep 工具所用的正则表达式文法。这相当于 basic 选项,附带以换行符 '\n' 作为另一种分隔符。
egrep 使用 POSIX 中 grep 工具带 -E 选项所用的正则表达式文法。这相当于 extended 选项,附带以换行符 '\n' 作为 '|' 之外的另一种分隔符。
文法变体 效果
icase 应当以不考虑大小写进行字符匹配。
nosubs 进行匹配时,将所有被标记的子表达式 (expr) 当做非标记的子表达式 (?:expr)。不将匹配存储于提供的 std::regex_match 结构中,且 mark_count() 为零。
optimize 指示正则表达式引擎进行更快的匹配,带有令构造变慢的潜在开销。例如这可能表示将非确定有限状态机转换为确定有限状态机。
collate 形如 "[a-b]" 的字符范围将对本地环境敏感。
multiline (C++17) 如果选择 ECMAScript 引擎,那么指定 ^ 应该匹配行首,而 $ 应该匹配行尾。

在文法选项 ECMAScriptbasicextendedawkgrepegrep 中最多只能选取一个。当未选择文法时假定选取 ECMAScript。其他选项作为文法变体生效,从而 std::regex("meow", std::regex::icase) 等价于 std::regex("meow", std::regex::ECMAScript|std::regex::icase)

参阅

控制正则表达式行为的通用选项
(typedef)