常用的正則匹配表達式
正則表達式--驗證手機號碼:13[0-9]{9}
實現手機號前帶86或是+86的情況:^((/+86)|(86))?(13)/d{9}$
電話號碼與手機號碼同時驗證:(^(/d{3,4}-)?/d{7,8})$|(13[0-9]{9})
提取信息中的網絡鏈接:(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+)
提取信息中的中國手機號碼:(86)*0*13/d{9}
提取信息中的中國固定電話號碼:(/(/d{3,4}/)|/d{3,4}-|/s)?/d{8}
提取信息中的中國電話號碼(包括移動和固定電話):(/(/d{3,4}/)|/d{3,4}-|/s)?/d{7,14}
提取信息中的中國郵政編碼:[1-9]{1}(/d+){5}
提取信息中的中國身份證號碼:/d{18}|/d{15}
提取信息中的整數:/d+
提取信息中的浮點數(即小數):(-?/d*)/.?/d+
提取信息中的任何數字 :(-?/d*)(/./d+)?
提取信息中的中文字符串:[/u4e00-/u9fa5]*
提取信息中的雙字節字符串 (漢字):[^/x00-/xff]*
用到的函數(第一個參數為正則表達式,第二個為字符串):
復制代碼代碼如下:
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' 建立變量。
Set regEx = New RegExp ' 建立正則表達式。
regEx.Pattern = patrn ' 設置模式。
regEx.IgnoreCase = True ' 設置是否區分字符大小寫。
regEx.Global = True ' 設置全局可用性。
Set Matches = regEx.Execute(strng) ' 執行搜索。
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