国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > regex > 正文

asp 圖片正則 替換,替換前檢查圖片是不是本地地址的方法

2020-01-20 22:23:40
字體:
來源:轉載
供稿:網友
直接用正則替換,但沒有判斷功能
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的說明文檔
//m.survivalescaperooms.com/article/15362.htm

下面由武林網測試代碼,大家可以做出函數
<%
content2="<img src='//m.survivalescaperooms.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://m.survivalescaperooms.com" then
picurl=tmpurl
else
picurl="http://img.VeVB.COm/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

%>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东台市| 厦门市| 新密市| 大宁县| 新平| 怀安县| 定襄县| 巴彦县| 崇礼县| 凤庆县| 海兴县| 怀远县| 习水县| 临海市| 芦溪县| 广昌县| 武宁县| 呼伦贝尔市| 思茅市| 长乐市| 潼关县| 惠州市| 临夏市| 景洪市| 宁晋县| 岳池县| 新昌县| 长宁县| 甘谷县| 同江市| 灵璧县| 陇川县| 安岳县| 电白县| 邹城市| 寿光市| 盐亭县| 长子县| 岑溪市| 江城| 陵川县|