如下代码:
<%
s="1348769887<br/>8769887<br/>134988727764"
s=RP(s)
response.Write s
%>
<script runat="server" language="jscript">
function RP(v) {
var whiterx = /(8769887|8769886)/;//修改你的这个正则如果还有其他白名单
return v.replace(/(\d{3})(\d{3,})/g, function ($0, $1, $2) {
if (whiterx.test($0)) return $0;//包含白名单中不替换
return $1 + '<font color="red">' + $2.replace(/\d/g, '*') + '</font>';
});
}
</script>
如果s字符串是这样: s = "1348769887<br/>8769887<br/>134988727764<br/><img src='8769887.jpg'>"
除图片之外的,其它要符合RP规则的。。其正则应该要怎么改? 谢谢!
------解决方案--------------------
<%
function RP(byval str)
if isnull(str) then exit function
dim re, reWhite, i, Matches, Match, MyArray()
set re = new RegExp
re.IgnoreCase = true
re.Global = true
re.Pattern = "(?:<img[\s\S]*?>)"
set reWhite = new RegExp
reWhite.Pattern = "8769887
------解决方案--------------------
8769886"
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.Pattern = "\d{4,}"
' 开始替换
Set Matches =re.Execute(str)
For Each Match in Matches
if not reWhite.test(Match.Value) then
str = replace(str, Match.Value, left(Match.Value, 3) & string(len(Match.Value)-3, "*"))
end if
Next
' 结束替换
if i > 0 then
for i = 0 to ubound(MyArray)
str = replace(str, "<@#"&i&"#@>", MyArray(i))
next
end if
RP = str
end function
s="1348769887<br/><img src='8769887.jpg'>8769887<br/>134988727764<br/><img src='87691887.jpg'>134988727764"
response.Write RP(s)
%>
重写了下。