名稱空間
變體
操作

std::basic_regex

來自 cppreference.com
< cpp‎ | regex
 
 
 
正則表示式庫
basic_regex
(C++11)
(C++11)
演算法
迭代器
異常
特性
常量
(C++11)
正則表示式語法
 
 
在標頭檔案 <regex> 中定義
template<

    class CharT,
    class Traits = std::regex_traits<CharT>

> class basic_regex;
(C++11 起)

類模板 basic_regex 提供一個用於儲存正則表示式的通用框架。

提供了用於常見字元型別的幾個 typedef

在標頭檔案 <regex> 中定義
型別 定義
std::regex std::basic_regex<char>
std::wregex std::basic_regex<wchar_t>

目錄

[編輯] 成員型別

成員型別 定義
value_type CharT
traits_type 特性
string_type Traits::string_type
locale_type Traits::locale_type
flag_type std::regex_constants::syntax_option_type

[編輯] 成員函式

構造 regex 物件
(public member function) [編輯]
析構 regex 物件
(public member function) [編輯]
賦值內容
(public member function) [編輯]
賦值內容
(public member function) [編輯]
觀察器
返回正則表示式中被標記的子表示式的數量
(public member function) [編輯]
返回語法標誌
(public member function) [編輯]
區域設定
獲取區域設定資訊
(public member function) [編輯]
設定區域設定資訊
(public member function) [編輯]
修改器
交換內容
(public member function) [編輯]

常量

語法選項 效果
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 引擎,指定 ^ 匹配行首,$ 匹配行尾。

ECMAScriptbasicextendedawkgrepegrep 中最多隻能選擇一個語法選項。如果未選擇語法,則假定選擇 ECMAScript。其他選項作為變體,因此 std::regex("meow", std::regex::icase) 等同於 std::regex("meow", std::regex::ECMAScript|std::regex::icase)

basic_regex 中的成員常量是名稱空間 std::regex_constants 中定義的 syntax_option_type 常量的副本。

[編輯] 非成員函式

特化 std::swap 演算法
(function template) [編輯]

[編輯] 推導指南(C++17 起)