199 字1 分钟
ASP 自动识别链接函数
找了很多地方,发现一个还不错的,不过多少有点问题,经过 zx 的指点,参照 Z-Blog 处理 UBB 的函数修改了一下,基本还算好用。
Function autoLink(str)str=" "&strSet re=new regExp '建立正则表达式对象regular expressionre.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=nothingautolink=trim(str)End Function主要是正则表达式的应用啊。