命名空间
变体
操作

std::basic_regex 常量

来自 cppreference.cn
< 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 使用Modified ECMAScript 正则表达式语法
basic 使用基本 POSIX 正则表达式语法(语法文档)。
extended 使用扩展 POSIX 正则表达式语法(语法文档)。
awk 使用 POSIX 中 awk 实用程序使用的正则表达式语法(语法文档)。
grep 使用 POSIX 中 grep 实用程序使用的正则表达式语法。这实际上与 basic 选项相同,但添加了换行符 '\n' 作为交替分隔符。
egrep 使用带有 -E 选项的 grep 实用程序在 POSIX 中使用的正则表达式语法。这实际上与 extended 选项相同,但除了 '|' 之外,还添加了换行符 '\n' 作为交替分隔符。
语法变体 效果
icase 字符匹配应不区分大小写地执行。
nosubs 执行匹配时,所有标记的子表达式 (expr) 都被视为非标记的子表达式 (?:expr)。没有匹配项存储在提供的 std::regex_match 结构中,并且 mark_count() 为零。
optimize 指示正则表达式引擎使匹配更快,但可能会以降低构造速度为代价。例如,这可能意味着将非确定性 FSA 转换为确定性 FSA。
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) [编辑]