正規表示式例子

2021-10-08 19:53:56 字數 1339 閱讀 4813

#include

"regex.hpp"

#include

#include

#include

#include

inttest_regex_match()

-\\d|\\d-\\d"};

// fixed telephone

std::regex re

(pattern);

std::vector str

;/* std::regex_match:

判斷乙個正規表示式(引數re)是否匹配整個字串行str,它主要用於驗證文字

注意,這個正規表示式必須匹配被分析串的全部,否則返回false;如果整個序列被成功匹配,返回true

*/for

(auto tmp : str)

return0;

}int

test_regex_search()

;// url

std::regex re

(pattern);

std::vector str

;/* std::regex_search:

類似於regex_match,但它不要求整個字串行完全匹配

可以用regex_search來查詢輸入中的乙個子串行,該子串行匹配正規表示式re

*/for

(auto tmp : str)

return0;

}int

test_regex_search2()

;// url

std::regex re

(pattern);

std::string str

; std::smatch results;

while

(std::

regex_search

(str, results, re)

)return0;

}int

test_regex_replace()

|\\dx"};

// id card

std::regex re

(pattern);

std::vector str

; std::string fmt

;/* std::regex_replace:

在整個字串行中查詢正規表示式re的所有匹配

這個演算法每次成功匹配後,就根據引數fmt對匹配字串進行替換

*/for

(auto tmp : str)

return0;

}int

test_regex_replace2()

``

正規表示式例子

前言 regular expressions 正規表示式,以下用re稱呼 對小弟來說一直都是神密的地帶,看到一些網路上的大大,簡單用re就決解了某些文字的問題,小弟便興起了學一學re的想法,但小弟天生就比較懶一些,總希望看有沒有些快速學習的方式,於是小弟又請出google大神,借由祂的神力,小弟在網...

Oracle 正規表示式例子

查詢value中不是純數字的記錄 select from fzq select from fzq where regexp like value,digit 以數字開頭,並且匹配多次,直到結尾 select from fzq where regexp like value,digit 以數字開頭,並...

正規表示式 例子學習

正規表示式是乙個程式設計的藝術,很難除錯,學習和理解,但強大的功能,仍吸引不少開發者編寫正規表示式。讓我們探索一下下面10個實際應用中的正規表示式。1.使用者名稱正規表示式模式 a z0 9 行開始 a z0 9 匹配列表中的字元,a z,0 9,下劃線,連字元 長度至少3個字元,最大長度為15 行...