当前位置:asp编程网>技术教程>Asp教程>  正文

给字符串中的网址加上超连接

2007-11-14 17:31:18   来源:本站原创    作者:佚名   浏览量:2478   收藏
<%
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="""&#38;Match.value&#38;""" target=""_blank"">"&#38;Match.Value&#38;"</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)
  %>


关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网