Function autoLink(str)
str=" "&str
Set re=new regExp '建立正则表达式对象regular expression
re.IgnoreCase=true '忽略大小写
re.Global=true '搜索匹配字串针对全部文本
'查找带协议前缀的链接
re.Pattern="(http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?)"
str=re.replace(str,"<a href='$1' target='_blank'>$1</a>")
'查找不带协议前缀的链接
re.Pattern="([^(http:\/\/)])(www\.([\w-]+\.)+[\w]+(\/[\w-]+)*[\/]?([\w-]+\.[\w]+)?(\?[\w]+=[\w]+(&[\w]+=[\w]+)*)?)"
str=re.replace(str,"$1<a href='http://$2' target='_blank'>$2</a>")
'查找邮件链接
re.Pattern="(mailto:)?([\w]+@([\w-]+\.)+[\w]+)"
str=re.replace(str,"<a href='mailto:$2'>$1$2</a>")
Set re=nothing
autolink=trim(str)
End Function