Namespaces
Variants

std:: basic_regex constants

From cppreference.net
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
Exceptions
Traits
Constants
(C++11)
Regex Grammar
定义于头文件 <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中带 -E 选项的 grep 工具采用的正则表达式语法。这实际上等同于 extended 选项,但额外将换行符 ' \n ' 作为 '|' 之外的备选分隔符。
语法变体 作用
icase 执行字符匹配时应忽略大小写。
nosubs 执行匹配时,所有标记子表达式 ( expr ) 均被视为非标记子表达式 (?: expr ) 。匹配结果不会存储到提供的 std::regex_match 结构中,且 mark_count() 返回零。
optimize 指示正则表达式引擎优化匹配速度,可能以增加构造时间为代价。例如可能将非确定性有限状态自动机转换为确定性有限状态自动机。
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 )

参见

控制正则表达式行为的通用选项
(类型定义)