4,008
社区成员
发帖
与我相关
我的任务
分享
<a href="111.htm">111</a><br>
<a href=’222.htm'>222</a><br>
<a href=333.htm class=23>333</a><br>
<a id="test" href="444.htm">444</a><br>
<a href="555.htm" id="test">555</a><br>
<a href=666.htm>666</a><br>
<a href="http://www.xxx.com/111.htm">111</a><br>
<a href=’http://www.xxx.com/222.htm'>222</a><br>
<a href=http://www.xxx.com/333.htm class=23>333</a><br>
<a id="test" href="http://www.xxx.com/444.htm">444</a><br>
<a href="http://www.xxx.com/555.htm" id="test">555</a><br>
<a href=http://www.xxx.com/666.htm>666</a><br>
dim str
str="<a href=""01.htm"">111111111111</a><hr><a href='02.htm'>22222222</a><hr><a href=03.htm class=23>3333333333</a><hr><a id=""test"" href=""01.htm"">44444444</a><hr><a href=""01.htm"" id=""test"">5555555555</a><hr><a href=03.htm>6666</a><hr>"
str=ReplaceTest("href=[""'“”]?([^\s""'“” >]+?)[""'“”> ]+?",str,"href=""http://www.XXX.com/$1""")
Response.Write(str)
Function ReplaceTest(patrn,str,replStr)
Dim regEx, str1 ' 建立变量。
str1=trim(str)
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = true ' 设置是否区分大小写。
regEx.Global = true
ReplaceTest = regEx.Replace(str1, replStr) ' 作替换。
set regEx=nothing '销毁正则表达式对象
End Function
a = "<a href=""111.htm"">111</a><br>"
a = a & vbcrlf & "<a href='222.htm'>222</a><br>"
a = a & vbcrlf & "<a href=333.htm class=23>333</a><br>"
a = a & vbcrlf & "<a id=""test"" href=""444.htm"">444</a><br>"
a = a & vbcrlf & "<a href=""555.htm"" id=""test"">555</a><br>"
a = a & vbcrlf & "<a href=666.htm>666</a><br>"
Dim regex
Set regex = New RegExp
regex.Pattern = "href=('|"")*([^>+""+']+)('|"")*"
regex.IgnoreCase = True
regex.Global = True
a = regex.Replace(a,"href=""http://www.xxx.com/$2""")
Set regex = Nothing
MsgBox a
Dim regex
Set regex = New RegExp
regex.Pattern = "href\=(?:""([^""]*)""|'([^']*)'|([^\s/>]+))"
regex.IgnoreCase = True
regex.Global = True
HTMLCODE = regex.Replace(HTMLCODE, "href=""http://www.xxx.com/$1$2$3""")
Set regex = Nothing