日期:2014-05-16 浏览次数:20398 次
function replaceNotInHref(str, word, reword, isGlobal)
dim re
set re = new RegExp
re.Pattern = word & "(?:(?=.*<a\b)|(?!.*?<\/a>))"
re.IgnoreCase = True
re.Global = isGlobal
replaceNotInHref = re.replace(str, reword)
end function
str = "123<a href='f'>金属123</a>金属123<a href='f'>金属</a>123金属"
response.write replaceNotInHref(str, "金属", "被替换了", false)
var str = "123<a href='f'>金属123</a>金属123<a href='f'>金属</a>123金属";
alert(str.replace(/(?=[^>]*(?=<(?!\/)
------解决方案--------------------
$))金属/g,'橡胶'))
<%
function replaceNotInHref(str, word, reword, isGlobal)
dim re, i, Matches, Match
set re = new RegExp
re.IgnoreCase = true
re.Global = true
re.Pattern = "(?:<a.*?>[\s\S]*?</a>)"
Set Matches =re.Execute(str)
i = 0
For Each Match in Matches
ReDim Preserve MyArray(i)
MyArray(i) = Match.Value
str = replace(str, Match.Value, "<@#"&i&"#@>")'
i = i + 1
Next
re.Global = isGlobal
re.Pattern = word
str = re.replace(str, reword)
if i > 0 then
for i = 0 to ubound(MyArray)
str = replace(str, "<@#"&i&"#@>", MyArray(i))
next
end if
replaceNotInHref = str
end function
str = "123<a href='f'>金属123</a>金属123<a href='f'>金属</a>123金属"
str1 = "123金属123金属1233"
response.write replaceNotInHref(str, "金属", "被替换了", false)
response.write "<br>"
response.write replaceNotInHref(str1, "金属", "被替换了", true)
%>
var str = "123<a href='f'>金属123</a>金属123<a href='f'>金属</a>123金属";
str = str.replace(/(<a[^>]+>.*?)金属(.*?<\/a>)/ig, "$1xxoo$2").replace(/金属/g, '我暈!').replace(/xxoo/ig, "金属");
alert(str);