使用Regex實現模式圖片新聞(加強).ASP

來源:互聯網
上載者:User
正則 客戶要求儲存原有的img已在的屬性,鬱悶,繼續改

代碼如下:


function shownew(content,ntype)

shownew = ""

if(ntype = 1) then

shownew = shownew &" <TABLE width=100% >"
shownew = shownew &"<TR>"
shownew = shownew &" <TD width=700 align=center style='word-break:break-all' valign=top>"&ShowPic(content)&"</TD>"
shownew = shownew &"</TR>"
shownew = shownew &"<TR>"
shownew = shownew &" <TD valign=top style='word-break:break-all'>"&OnlyWord(content)&"</TD>"
shownew = shownew &"</TR>"
shownew = shownew &"</TABLE>"


elseif (ntype = 2) then


shownew = shownew &" <TABLE width='100%'>"

shownew = shownew &"<TR>"
shownew = shownew &" <TD style='word-break:break-all' valign=top>"&OnlyWord(content)&"</TD>"
shownew = shownew &"</TR>"
shownew = shownew &"<TR>"
shownew = shownew &" <TD align=center width=700 valign=top style='word-break:break-all'>"&ShowPic(content)&"</TD>"
shownew = shownew &"</TR>"
shownew = shownew &"</TABLE>"

elseif (ntype = 3) then


shownew = shownew &"<TABLE>"

shownew = shownew &"<TR>"
shownew = shownew &"<TD width=100 align=center valign=top>"&ShowPic(content)&"</TD>"

shownew = shownew &"<TD width=80% style='word-break:break-all' valign=top>"&OnlyWord(content)&"</TD>"


shownew = shownew &"</TR>"
shownew = shownew &"</TABLE>"

elseif (ntype = 4) then

shownew = shownew &"<TABLE>"

shownew = shownew &"<TR>"

shownew = shownew &"<TD width=80% valign=top style='word-break:break-all'>"&OnlyWord(content)&"</TD>"
shownew = shownew &"<TD width=100 valign=top align=center>"&ShowPic(content)&"</TD>"

shownew = shownew &"</TR>"
shownew = shownew &"</TABLE>"
else
shownew = shownew &content
end if

end function

'顯示提取的圖片
function ShowPic(strng)

set regEx2 = new RegExp

regEx2.Pattern = "(src=)('|"&CHR(34)&"| )?(.[^'| |"&CHR(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)('|"&CHR(34)&"| |>)?" '設定模式。
regEx2.IgnoreCase = true '設定是否區分字元大小寫。
regEx2.Global = True '設定全域可用性。

ShowPic = ""
ImageUrl= RegExpExecute(strng)

ImageUrls = Split(ImageUrl,"{|LDIV|}")


for i = LBound(ImageUrls) to (UBound(ImageUrls) - 1)


Set Matches2 = regEx2.Execute(ImageUrls(i)) '執行搜尋。


For Each Match2 in Matches2 '遍曆匹配集合。

'全Img標籤
newpic = LCase(ImageUrls(i))

'如果沒有自訂BORDER增加BOrder=0,其它原屬性保留

if(instr(newpic,"border")=false) then newpic = left(newpic,len(newpic)-1) + " border='0' >"
if(instr(newpic,"width")=false) then newpic = left(newpic,len(newpic)-1) + " width='200' >"

newpic = "<a style='padding:20px' href='"&Match2.SubMatches(2)&Match2.SubMatches(3)&Match2.SubMatches(4)&"' >"& newpic & "</a>"

ShowPic = ShowPic & newpic
Next


next

Set regEx2 = nothing
end function


'從內容中提取圖片
Function RegExpExecute(strng)
Dim regEx, Match, Matches '建立變數。
Set regEx = New RegExp '建立Regex。

regEx.Pattern = "(<)(.[^<]*)(src=)('|"&CHR(34)&"| )?(.[^'|\s|"&CHR(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)('|"&CHR(34)&"|\s|>)(.[^>]*)(>)" '設定模式。


regEx.IgnoreCase = true '設定是否區分字元大小寫。
regEx.Global = True '設定全域可用性。
Set Matches = regEx.Execute(strng) '執行搜尋。
For Each Match in Matches '遍曆匹配集合。
values=values&Match.Val



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.