首页  »  网页设计教程  »  利用正则表达式实现模式图片新闻-ASP

利用正则表达式实现模式图片新闻-ASP

浏览数:共 556 次     评论:共 0 条     发布日期:2011-08-17     分类:asp

shownew = shownew &;"<tr>"
shownew = shownew &;" <td width=600 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 &;" <td style="word-break:break-all" valign=top>"&;onlyword(content)&;"</td>"
shownew = shownew &;"</tr>"
shownew = shownew &;"<tr>"
shownew = shownew &;" <td width=600 valign=top style="word-break:break-all">"&;showpic(content)&;"</td>"
shownew = shownew &;"</tr>"
shownew = shownew &;"</table>"

shownew = shownew &;"<table>"

shownew = shownew &;"<td width=100 valign=top>"&;showpic(content)&;"</td>"

shownew = shownew &;"</tr>"
shownew = shownew &;"</table>"

shownew = shownew &;"<td width=100 valign=top>"&;showpic(content)&;"</td>"

shownew = shownew &;"</table>"
else
shownew = shownew &; "<table><tr><td style="word-break:break-all">"&;content&;"</td></tr></table>"
end if

function showpic(strng)

imageurl= regexpexecute(strng)


ageurls) to (ubound(imageurls) - 1)


end function

"从内容中提取图片
function regexpexecute(strng)
dim regex, match, matches "建立变量。
set regex = new regexp "建立正则表达式。
regex.pattern = "(src=)("|"&;chr(34)&;"| )?(.[^"|s|"&;chr(34)&;"]*)(.)(jpg|gif|png|bmp|jpeg)("|"&;chr(34)&;"|s|>)?" "设置模式。
" regex.pattern = "(src=)("|"&;chr(34)&;"| )?(.[^"| |"&;chr(34)&;"]*)(.)(jpg|gif|png|bmp|jpeg)("|"&;chr(34)&;"| |>)?" "设置模式。
"regex.pattern = "(s|s)(r|r)(c|c)=("|"+chr(34)+")(w||/|.)+("|"+chr(34)+"| *|>)?" "设置模式。
regex.ignorecase = true "设置是否区分字符大小写。
regex.global = true "设置全局可用性。
set matches = regex.execute(strng) "执行搜索。
for each match in matches "遍历匹配集合。
values=values&;match.submatches(2)&;match.submatches(3)&;match.submatches(4)&;"<br>"
next
regexpexecute = values
end function

function onlyword(strng)
set re=new regexp
re.ignorecase =tr



上一篇:动态网站首页的静态生成方式
下一篇:让你的WAP网站有更好的兼容性