asp 图片正则 替换,替换前检查图片是不是本地地址的方法

时间:2021-05-28

直接用正则替换,但没有判断功能
FunctionFormatImg(content)
dimre
Setre=newRegExp
re.IgnoreCase=true
re.Global=True
re.Pattern="(script)"
Content=re.Replace(Content,"script")
re.Pattern="<img.[^>]*src(=|)(.[^>]*)>"
Content=re.replace(Content,"<imgsrc=$2style=""cursor:pointer""alt=""在新窗口中打开浏览""onclick=""javascript:window.open(this.src);""onload=""javascript:resizepic(this)""border=""0""/>")
setre=nothing
FormatImg=content
EndFunction
这段代码将内容中的图片替换成<imgsrc=$2style="cursor:pointer"alt="在新窗口中打开浏览"onclick="javascript:window.open(this.src);"onload="javascript:resizepic(this)"border="0"/>这中形式的,
我现在需要提取$2的前7个字符,用来判断是否需要被替换,如果前7=特定的字符,就不要替换,但获取$2的前7无法。大家有什么办法支下招撒?

主要是参考了下面的代码,大家可以看下
'连接
re.Pattern="\[url=(.[^\]]*)\](.[^\[]*)\[\/url]"
SetstrMatchs=re.Execute(strContent)
ForEachstrMatchinstrMatchs
tmpStr1=checkURL(strMatch.SubMatches(0))
tmpStr2=strMatch.SubMatches(1)
strContent=replace(strContent,strMatch.Value,"<atarget=""_blank""href="""&tmpStr1&""">"&tmpStr2&"</a>",1,-1,0)
Next
这里是正则的Matchs的说明文档
https:///indeximg/logo.GIF'width=200/>"
dimre
Setre=newRegExp
re.IgnoreCase=true
re.Global=True
re.Pattern="<img.[^>]*src(=|)(.[^>]*)[/]?>"
setMatches=re.execute(content2)
ForEachstrMatchinMatches
tmpStr1=(strMatch.SubMatches(1))
tmpurl=replace(replace(tmpStr1,"'",""),"""","")
//response.writeleft(tmpurl,20)
ifleft(tmpurl,19)="https://www.jb51.net"then
picurl=tmpurl
else
picurl="http://img.jb51.net/showpic.asp?url="&tmpurl
endif
Content=replace(Content2,strMatch.Value,"<imgsrc="&picurl&"style=""cursor:pointer""alt=""在新窗口中打开浏览""onclick=""javascript:window.open(this.src);""onload=""javascript:resizepic(this)""border=""0""/>")
Next
response.writeContent
setre=nothing

%>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章