直接用正则替换,但没有判断功能
Function FormatImg(content)
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="(script)"
Content=re.Replace(Content,"script")
re.Pattern="<img.[^>]*src(=| )(.[^>]*)>"
Content=re.replace(Content,"<img src=$2 style=""cursor: pointer"" alt=""在新窗口中打开浏览"" onclick=""javascript:window.open(this.src);"" onload=""javascript:resizepic(this)"" border=""0""/>")
set re = nothing
FormatImg = content
End Function
这段代码将内容中的图片替换成 <img src=$2 style="cursor: pointer" alt="在新窗口中打开浏览" onclick="javascript:window.open(this.src);" onload="javascript:resizepic(this)" border="0"/> 这中形式的,
我现在需要提取$2的前7个字符,用来判断是否需要被替换,如果前7=特定的字符,就不要替换,但获取$2的前7 无法。大家有什么办法支下招撒?
主要是参考了下面的代码,大家可以看下
'连接
re.Pattern = "\[url=(.[^\]]*)\](.[^\[]*)\[\/url]"
Set strMatchs=re.Execute(strContent)
For Each strMatch in strMatchs
tmpStr1=checkURL(strMatch.SubMatches(0))
tmpStr2=strMatch.SubMatches(1)
strContent=replace(strContent,strMatch.Value,"<a target=""_blank"" href="""&tmpStr1&""">"&tmpStr2&"</a>",1,-1,0)
Next
这里是正则的Matchs的说明文档
http://www.zzvips.com/article/87034.html
下面由服务器之家测试代码,大家可以做出函数
<%
content2="<img src='http://www.zzvips.com/images/logo.gif' width=100 />中间一些内容<img src='http://www.kanshule.com/indeximg/logo.GIF' width=200 />"
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="<img.[^>]*src(=| )(.[^>]*)[/]?>"
set Matches=re.execute(content2)
For Each strMatch in Matches
tmpStr1=(strMatch.SubMatches(1))
tmpurl=replace(replace(tmpStr1,"'",""),"""","")
//response.write left(tmpurl,20)
if left(tmpurl,19)="http://www.zzvips.com" then
picurl=tmpurl
else
picurl="http://img.123.net/showpic.asp?url="&tmpurl
end if
Content=replace(Content2,strMatch.Value,"<img src="&picurl&" style=""cursor: pointer"" alt=""在新窗口中打开浏览"" onclick=""javascript:window.open(this.src);"" onload=""javascript:resizepic(this)"" border=""0""/>")
Next
response.write Content
set re = nothing
%>
asp 图片正则 替换,替换前检查图片是不是本地地址的方法
2020-07-21 15:23正则表达式教程网 正则表达式
这个图片正则先检查图片的地址,不是本地的则用本地的asp突破盗链,方便使用,注意是答chinaz的朋友问的一个问题
延伸 · 阅读
- 2022-03-10Python全栈之路正则函数
- 2022-03-07如何替换@PathVariable中的变量
- 2022-02-28一个关于JS正则匹配的踩坑记录
- 2022-02-13Python中搜索和替换文件中的文本的实现(四种)
- 2022-01-24Python如何将给定字符串中的大写英文字母按以下
- 2022-01-19Python常用正则函数使用方法详解
- 正则表达式
常用正则表达式语法例句
本文主要分享一些常用正则表达式语法例句,具有一定的参考价值,有需要的朋友可以了解下...
- 正则表达式
js通过正则匹配没有内容的空标签
这篇文章主要介绍了js通过正则匹配没有内容的空标签,需要的朋友可以参考下...
- 正则表达式
JavaScript 正则表达式 验证整数、小数、实数、有效位小数最简单
JavaScript 正则表达式 验证整数、小数、实数、有效位小数最简单,输入完按回车后即可验证!(自认为最简单!)...
- 正则表达式
正则表达式re.sub替换不完整的问题及完整解决方案
re.sub是个正则表达式方面的函数,用来实现通过正则表达式,实现比普通字符串的replace更加强大的替换功能。这篇文章主要介绍了正则表达式re.sub替换不完...
- 正则表达式
JS正则表达式验证数字(非常全)
正则表达式,又称规则表达式,在项目中经常会用到正则表达式,今天小编抽空给大家分享js正则表达式验证数字的方法,感兴趣的朋友参考下吧...
- 正则表达式
解决preg_match匹配过多字符长度的限制的思路分析
今天在写采集程序的时候,使用到了preg_match,但是有几个页面始终采集不下来。反复看了N遍的正则,没有发现有问题。于是开始怀疑preg_match是否对匹配的...
- 正则表达式
asp去除html标记与空格的正则
用asp实现的去除内容的html标记和空格的实现代码,正在学习正则表达式的朋友可以参考下...
- 正则表达式
正则表达式概述 什么是正则表达式
正则表达式就是用某种模式去匹配一类字符串的公式,主要用来描述字符串匹配的工具...