常用的正則匹配表達(dá)式
正則表達(dá)式–驗(yàn)證手機(jī)號(hào)碼:13[0-9]{9}
實(shí)現(xiàn)手機(jī)號(hào)前帶86或是+86的情況:^((+86)|(86))?(13)d{9}$
電話號(hào)碼與手機(jī)號(hào)碼同時(shí)驗(yàn)證:(^(d{3,4}-)?d{7,8})$|(13[0-9]{9})
提取信息中的網(wǎng)絡(luò)鏈接:(h|H)(r|R)(e|E)(f|F) *= *(‘|”)?(w|\|/|.)+(‘|”| *|>)?
提取信息中的郵件地址:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
提取信息中的圖片鏈接:(s|S)(r|R)(c|C) *= *(‘|”)?(w|\|/|.)+(‘|”| *|>)?
提取信息中的IP地址:(d+).(d+).(d+).(d+)
提取信息中的中國(guó)手機(jī)號(hào)碼:(86)*0*13d{9}
提取信息中的中國(guó)固定電話號(hào)碼:((d{3,4})|d{3,4}-|s)?d{8}
提取信息中的中國(guó)電話號(hào)碼(包括移動(dòng)和固定電話):((d{3,4})|d{3,4}-|s)?d{7,14}
提取信息中的中國(guó)郵政編碼:[1-9]{1}(d+){5}
提取信息中的中國(guó)身份證號(hào)碼:d{18}|d{15}
提取信息中的整數(shù):d+
提取信息中的浮點(diǎn)數(shù)(即小數(shù)):(-?d*).?d+
提取信息中的任何數(shù)字 :(-?d*)(.d+)?
提取信息中的中文字符串:[u4e00-u9fa5]*
提取信息中的雙字節(jié)字符串 (漢字):[^x00-xff]*
用到的函數(shù)(第一個(gè)參數(shù)為正則表達(dá)式,第二個(gè)為字符串):
Dim regEx, Match, Matches ‘ 建立變量。
Set regEx = New RegExp ‘ 建立正則表達(dá)式。
regEx.Pattern = patrn ‘ 設(shè)置模式。
regEx.IgnoreCase = True ‘ 設(shè)置是否區(qū)分字符大小寫。
regEx.Global = True ‘ 設(shè)置全局可用性。
Set Matches = regEx.Execute(strng) ‘ 執(zhí)行搜索。
For Each Match in Matches ‘ 遍歷匹配集合。
‘RetStr = RetStr & “Match found at position ”
‘RetStr = RetStr & Match.FirstIndex & “. Match Value is ‘”
RetStr = RetStr & Match.Value
Next
RegExpTest = RetStr
End Function