2006-5-7 ASP VBSCRIPT 正则表达式之 替换 URL 与 EMAIL 地址为热链接 By Stabx
Regular Expression
1. 匹配 URL 并替换, www. 不超过四可正常工作, 或者说不超过三级域名, 本正则可正常工作
2. email 替换操作, 三级域名或以内, 本正则正常工作
---/---------------------------------------------------------
2. email 替换操作, 三级域名或以内, 本正则正常工作
'email 替换操作, email 替换为 <a href=mailto:email>email</a>
Set re = New RegExp
re.Pattern = "([\w-]+\.+[\w-]+\@+)([\w-]+\.+[\w-]+\.+|[\w-]+\.+)([\w{1}][\w{2}][\w{3}]|[\w{1}][\w{2}])"
re.Global = true
re.IgnoreCase = true
result = re.Replace(result,"<a href=mailto:$1$2$3>$1$2$3</a>")
----------------------
'EMAIL 解码
Set re = New RegExp
re.Pattern = "(\<a href\=mailto\:)([\w-]+\.+[\w-]+\@+)([\w-]+\.+[\w-]+\.+|[\w-]+\.+)([\w{1}][\w{2}][\w{3}]|[\w{1}][\w{2}])(\>)(.*)(\<\/a\>)"
re.Global = true
re.IgnoreCase = true
Str = re.Replace(Str,"$6")
1. 匹配 URL 并替换, www. 不超过四可正常工作, 或者说不超过三级域名, 本正则可正常工作
'url 替换操作, www 替换为 <a href=http://www>www</a>
Set re = New RegExp
re.Pattern = "(http\:\/\/|^http\:\/\/)([\w-]+\.+[\w-]+\.+[\w-]+\.+[\w-]+|[\w-]+\.+[\w-]+\.+[\w-]+)(/[\w-./?%&=]*)?"
re.Global = true
re.IgnoreCase = true
result = re.Replace(result,"<a href=http://$2$3 target=_blank>$1$2$3</a>")
----------------------
'URL 解码
Set re = New RegExp
re.Pattern = "(\<a href\=\http\:\/\/)([\w-]+\.+[\w-]+\.+[\w-]+\.+[\w-]+|[\w-]+\.+[\w-]+\.+[\w-]+)(/[\w-./?%&=]*)?( target\=\_blank\>)(http\:\/\/|^http\:\/\/)([\w-]+\.+[\w-]+\.+[\w-]+\.+[\w-]+|[\w-]+\.+[\w-]+\.+[\w-]+)(/[\w-./?%&=]*)?(/[\w-./?%&=]*)(\<\/a\>)"
re.Global = true
re.IgnoreCase = true
Str = re.Replace(Str,"$5$6$7$8")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' subject : 2006-5-7 ASP VBSCRIPT 正则表达式之 替换 URL 与 EMAIL 地址为热链接 By Stabx
'
' writer : Stabx<shawl.qiu@gmail.com>
'
' blog : http://blog.csdn.net/btbtd \ http://btbtd.exblog.jp/
'
' blog/site : Phoenix.GI - P.GI / \ 绿色学院 - Green Institute
'
' date : 2006-5-7
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''