Quantcast
Channel: 心跳论坛--『网络技术』最新20篇论坛主题-全文
Viewing all articles
Browse latest Browse all 19

asp为关键字添加超链接,并正则排除A标签实例

$
0
0

下午群里有网友需要实现这个功能,下班的时候写了一个演示

 

 

<%
Dim str
str = "随着昨晚<a href=""http://www.icbc.com.cn"">中国工商银行</a>和中国银行年报出炉,<a class=""abc"" href='http://www.ccb.com.cn' target=_blank>中国建设银行</a>表示压力很大"
Function xt_replace(str, temp, re1, re2)
 Dim re,matches
 Set re = new regexp
 re.pattern = "<a.+?href=[""|'](.+?)[""|'][^\>]*>(.+?)</a>"
 re.ignorecase = True
 re.global = True

 Set matches = re.execute(str)

 For Each match In matches
  str = Replace(str, match.value, Replace(match.value, re1, temp))
 Next
 Set matches = Nothing
 Set re = Nothing
 xt_replace = Replace(Replace(str, re1, re2), temp, re1)
End Function

Response.Write(xt_replace(str, "xintiao", "银行", "<a href=""#"">银行</a>"))
%>


Viewing all articles
Browse latest Browse all 19

Latest Images

Trending Articles





Latest Images