正文

给字符串中的网址加上超连接2007-06-18 11:46:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/wangsdong/26872.html

分享到:

<%
Function regExReplace(sSource,patrn, replStr)
Dim regEx, str1
str1 = sSource
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
regExReplace = regEx.Replace(str1, replStr)
End Function


Function RegExpTest(strng,s)
strng1=strng
Dim regEx, Match, Matches   ' 建立变量。
Set regEx = New RegExp   ' 建立正则表达式。
regEx.Pattern = s   ' 设置模式。
regEx.IgnoreCase = True   ' 设置是否区分大小写。
regEx.Global = True   ' 设置全局替换。
Set Matches = regEx.Execute(strng)   ' 执行搜索。
For Each Match in Matches   ' 遍历 Matches 集合。
strng1=regExReplace(strng1,Match.value,"<a href="""&Match.value&""" target=""_blank"">"&Match.Value&"</a>")
Next
RegExpTest = strng1
end Function

str="http://www.yahoo.com.cn雅虎http://www.sina.com.cn新浪http://hao123.com好123"
s="((http:[/][/]|www.)([a-z]|[A-Z]|[0-9]|[/.]|[~])*)"
response.write RegExpTest(str,s)
  %>

阅读(3596) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册