名稱空間
變體
操作

std::basic_regex 常量

來自 cppreference.com
< 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) [編輯]