下午群里有网友需要实现这个功能,下班的时候写了一个演示
<%
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>"))
%>