正則 客戶要求儲存原有的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