avatar

正则表达式检索图片地址

正则表达式检索图片地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<%
Set conn=server.CreateObject("adodb.connection")
conn.open "provider=microsoft.jet.oledb.4.0;data source="&server.mappath("/test/data.mdb")
Set rs=server.CreateObject("adodb.recordset")
sqlstr="select * from wenzhang"
rs.open sqlstr,conn,1,1
%>
<body>
<%
dim src
content=rs("neirong")
Str = Content
Set regEx = New RegExp '建立正则表达式。
regEx.Pattern = "(<img)(.[^<>]*)(src=)('|"&CHR(34)&"| )?(.[^'|\s|"&CHR(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)('|"&CHR(34)&"|\s|>)(.[^>]*)(>)" '设置模式。
regEx.IgnoreCase = True '设置是否区分字符大小写。
regEx.Global = True '设置全局可用性。
Set Matches = regEx.Execute(Str) '执行搜索。

For Each Match in Matches '遍历匹配集合。
'输入图片地址
Response.Write "<img src='"&Match.SubMatches(4)&"."&Match.SubMatches(6)&"'>" '显示图片
Response.Write Match.SubMatches(4)&"."&Match.SubMatches(6)&"<br>" '图片地址
Next

Set Match=Matches(0) '显示第一张
Response.Write "<img src='"&Match.SubMatches(4)&"."&Match.SubMatches(6)&"'>" '显示图片
%>
文章作者: pengweifu
文章链接: https://www.pengwf.com/2011/04/09/web/ASP-RegEx-Filter-Image/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 麦子的博客
打赏
  • 微信
    微信
  • 支付宝
    支付宝

评论