c 11 正規表示式(re)

2021-07-14 21:06:10 字數 817 閱讀 5650

//#include 

//using namespace boost;

#include

#include

#include

using

namespace

std;

void regex_test()

//如果整個輸入序列與表示式匹配,則regex_match函式返回true

if (regex_match(test_str, r))

else

//regex迭代器:sregex_iterator(b,e,r),來獲取所有匹配。

for (sregex_iterator ite(test_str.begin(), test_str.end(), r), end_ite; ite != end_ite; ++ite)

//子表示式:模式通常包含乙個或多個子表示式,通常用括號表示子表示式

//子表示式常見用途是驗證必須匹配特定格式的資料(如**號碼,ip位址等)

pattern = "(\\()?(\\d)(\\))?([-. ])?(\\d)";

regex re_tell(pattern);

string tell_str("123-1234567");

if (regex_match(tell_str, re_tell))

else

//string fmt("$2.$5.");

//cout << regex_replace(tell_str, re_tell, fmt) << endl;

//ip

}

C 11正規表示式

優勢 使得字串的處理更加簡單 一些相關的操作 驗證 檢查字串是否是想要的合法性 決策 判斷乙個輸入標書哪種字串 解析 從輸入的字串中查詢自己想要的資訊 轉換 搜尋字串,並將字串替換為新的格式化的字串 遍歷 搜尋字串所有出現的地方 符號化 根據一組分隔符將乙個字串分解為多個子字串 一些重要術語 模式 ...

c 11 正規表示式

include include 正規表示式標頭檔案 using namespace std regex search 檢索 regex replace 將檢索到的物件進行替換替換 match 是否匹配 void main cout 正規表示式實現字串的替換 void main 匹配時間 void m...

C 11 正規表示式

0.常用正規表示式 中文字元 u4e00 u9fa5 雙位元組字元 包括漢字在內 x00 xff 空白符 n s r 國內 號碼 d d d 18位身份證號 d d d d d 0 9 x 年 月 日 格式日期 0 9 1 9 0 9 1 9 0 9 0 9 1 9 0 9 1 9 0 9 0 13...