|
正则表达式(2) End Function <SCRIPT LANGUAGE=vbs> a="A1B2C3" Function F(S,P) Dim regEx, Match, Matches ' 建立变量。 Set regEx = New RegExp ' 建立正则表达式。 regEx.Pattern = P ' 设置模式。 regEx.IgnoreCase = True ' 设置是否区分字符大小写。 regEx.Global = True ' 设置全局可用性。 Set Matches = regEx.Execute(S) ' 执行搜索。 For Each Match in Matches ' 遍历匹配集合。 S =replace(S,Match.Value,"") Next F = S End Function MsgBox F(a,"\d") </SCRIPT> 求一个正则表达式的模式字符串,匹配下列字符串 href="CSdn.net/abc.jpg">http://www.csdn.net/abc.jpg" 就是匹配以href=开头,.jpg或者.gif,.bmp,.png等图片扩展名结束的字符
但是下面的情况不可以匹配: href=imageView.ASP?abc.jpg,就是说字符中含有.asp,.PHP,.jsp等不匹配 具体来说就是一个html格式的字符串,里面有一些链接点击后显示图片,现在要把这些链接替换成ASP页面(imageView.asp),然后页面中显示图片,图片的url用imageView.asp?url=abc.jpg这样的参数传递到imageView.asp '=================================================== '函数名:replaceImageView '作 用:把图片链接替换成网页链接,网页中显示图片 '参 数:strContent ----------- 要替换的html字符串 '=================================================== function replaceImageView( strContent ) Set re = new RegExp re.IgnoreCase = True re.Global = True re.Pattern = "(href=)(S*)((\w)+[.]{1}(jpgjpeggifbmppng))" Set imageLink = re.Execute( strContent ) i = 1 for each imageLinkUrl in imageLink tempUrl = Replace( imageLinkUrl, "href=", "") tempUrl = Replace( tempUrl, """", "" )
|