在VB中判断URL的正则表达式
- Public Function IsUrl(ByVal strTmp As String) As Boolean
- '作用:判断是否是网络地址
- '参数:strTmp:传入字符串
- '
- On Error GoTo Z
- Dim objIntPattern
- IsUrl = False
- Set objIntPattern = New RegExp
- objIntPattern.Pattern = "^((https|http|ftp|rtsp|mms)?://){0,1}" & _
"(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" & _ 'ftp的user@
"(((2[0-4]/d|25[0-5]|[01]?/d/d?)/.){3}(2[0-4]/d|25[0-5]|[01]?/d/d?)" & _ 'IP形式的URL- 199.194.52.184
"|" & _ '允许IP和DOMAIN(域名)
"(([0-9a-zA-Z_!~*'()-]+/.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]/.[a-zA-Z]{2,6}))" & _ '域名
"(:[0-9]{1,4})?" & _ '端口- :80
"((/?)|" & _
"(/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+/?)$"
objIntPattern.Global = True - IsUrl = objIntPattern.Test(strTmp)
- Set objIntPattern = Nothing
- Exit Function
- Z:
- IsUrl = False
- End Function