C++ 参考手册

位置:首页 > C++ 参考手册 >正则表达式库 >std::basic_regex > std::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;
static constexpr std::regex_constants::syntax_option_type multiline =
    std::regex_constants::multiline;
(C++17 起)

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

这些常量复制自 std::regex_constants

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

ECMAScript, basic, extended, awk, grep, egrep 必须选取至多一个文法选项。若不选取文法选项,则设定为选取 ECMAScript 。其他选项作为修饰符工作,从而 std::regex("meow", std::regex::icase) 等价于 std::regex("meow", std::regex::ECMAScript|std::regex::icase)

参阅

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