命名空间
变体
操作

std::basic_regex 常量

来自 cppreference.cn
< cpp‎ | regex‎ | basic_regex
 
 
 
正则表达式库
(C++11)
算法
迭代器
异常
特性
常量
(C++11)
正则表达式语法
 
 
在头文件 <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 使用 POSIX 中 `grep` 工具(带 `-E` 选项)所使用的正则表达式语法。这与 `extended` 选项基本相同,但除了 '|' 之外,新增了换行符 '\n' 作为交替分隔符。
语法变体 效果
icase 字符匹配应不区分大小写。
nosubs 执行匹配时,所有标记的子表达式 `(expr)` 都被视为非标记子表达式 `(?:expr)`。没有匹配项存储在提供的 std::regex_match 结构中,且 mark_count() 为零。
optimize 指示正则表达式引擎加快匹配速度,潜在代价是构造速度变慢。例如,这可能意味着将非确定性 FSA 转换为确定性 FSA。
collate 形式为 "[a-b]" 的字符范围将对区域设置敏感。
multiline (C++17 起) 如果选择 ECMAScript 引擎,指定 ^ 匹配行首,$ 匹配行尾。

在 `ECMAScript`、`basic`、`extended`、`awk`、`grep`、`egrep` 中,最多只能选择一个语法选项。如果未选择任何语法,则假定选择了 `ECMAScript`。其他选项作为变体,例如 std::regex("meow", std::regex::icase) 等同于 std::regex("meow", std::regex::ECMAScript|std::regex::icase)

[编辑] 参见

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