找了很多地方,发现一个还不错的,不过多少有点问题,经过zx的指点,参照Z-Blog处理UBB的函数修改了一下,基本还算好用。
做“碎碎念”那个页面时用到的,就像饭否/叽歪一样,可以识别链接 http://www.wilf.cn/plugin/fanfou/
ASP代码
- 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