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 使用有改動的 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 指示正則表達式引擎進行更快的匹配,帶有令構造變慢的潛在開銷。例如這可能表示將非確定有限狀態機轉換為確定有限狀態機。
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) [編輯]