时间: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邮箱联系删除。
php替换文章中的图片路径,下载图片到本地服务器/***获取替换文章中的图片路径*@paramstring$xstr内容*@paramstring$oriweb
本文实例讲述了JavaScript正则表达式替换字符串中图片地址(imgsrc)的方法。分享给大家供大家参考,具体如下:今天开发中遇到一个问题:如何替换一段HT
亲,请进入【卖家中心】-【图片空间】找到图片,鼠标移到图片上在左上角进行勾选,点击功能栏中的“替换”从本地电脑中进行上传替换图片温馨提醒:1.宝贝主图不支持替换
ASP通过函数来实现替换、保存远程图片,完成自动采集图片、提取图片的功能,函数中自动判断重复图片,智能分析链接路径,并转成成相对的图片地址保存在你指定的网站目录
内涵:正则匹配,正则替换,页面抓取,图片保存。实用的第一次Python代码参考#!/usr/bin/envpythonimporturllibimportrex