手机
当前位置:查字典教程网 >编程开发 >正则表达式 >asp下正则实现URL自动链接的一个函数
asp下正则实现URL自动链接的一个函数
摘要:复制代码代码如下:FunctionAutoLinkURLs(strString)Dimmatch,matches,offset,url,em...

复制代码 代码如下:

FunctionAutoLinkURLs(strString)

Dimmatch,matches,offset,url,email,link,relnkAutoLinkURL

relnkAutoLinkURL="<ahref=""[[%URL%]]"">[[%URLText%]]</a>"

IfNotIsObject(regExp)ThenSetregExp=NewRegExp

regExp.Global=True

regExp.IgnoreCase=True

'LookforURLs

regExp.Pattern="(((ht|f)tps?://)|(www.))([w-]+.)+[w-:]+(/[w-./?%#;&=]*)?"

Setmatches=regExp.Execute(strString)

offset=0

ForEachmatchinmatches

url=match

IfLeft(url,4)="www."Thenurl="http://"&url

link=Replace(Replace(relnkAutoLinkURL,"[[%URLText%]]",match),"[[%URL%]]",url)

strString=Mid(strString,1,match.FirstIndex+offset)&link&Mid(strString,match.FirstIndex+1+match.Length+offset,Len(strString))

offset=offset+Len(link)-Len(match)

Next

'Lookforemails

regExp.Pattern="[A-Za-z0-9_+-.']+@w+([-.]w+)*.w+([-.]w+)*"

Setmatches=regExp.Execute(strString)

offset=0

ForEachmatchinmatches

email=match

link=Replace(Replace(relnkAutoLinkURL,"[[%URLText%]]",match),"[[%URL%]]","mailto:"&email)

strString=Mid(strString,1,match.FirstIndex+offset)&link&Mid(strString,match.FirstIndex+1+match.Length+offset,Len(strString))

offset=offset+Len(link)-Len(match)

Next

AutoLinkURLs=strString

EndFunction

【asp下正则实现URL自动链接的一个函数】相关文章:

使用正则表达式匹配[***]样式的字符串

[php]正则表达式的五个成功习惯

javascript之正则表达式基础知识小结

正则表达式的字符串替换方法

notepad++ 等用正则表达式自动添加sql引号的技巧

Javascript里的两种使用正则的方法

[js]一个只删除所有font标签的正则函数

javascript 正则 判断是否是数字的脚本

javascript下正则匹配百分比的代码

PHP中基于perl的正则表达式处理函数

精品推荐
分类导航