当前位置:K88软件开发文章中心编程语言AspAsp01 → 文章内容

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

减小字体 增大字体 作者:佚名     来源:asp编程网  发布时间:2018-12-30 8:29:56

<
%
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 
 
 
&
#39
 
建立变量。
Set 
regEx 

New 
RegExp 
 
 
&
#39
 
建立正则表达式。
regEx.Pattern 


 
 
&
#39
 
设置模式。
regEx.IgnoreCase 

True 
 
 
&
#39
 
设置是否区分大小写。
regEx.Global 

True 
 
 
&
#39
 
设置全局替换。
Set 
Matches 

regEx.Execute(strng) 
 
 
&
#39
 
执行搜索。
For 
Each 
Match 
in 
Matches 
 
 
&
#39
 
遍历 
Matches 
集合。
strng1=regExReplace(strng1,Match.value,"
<

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)
 
 
%>



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