下面这段子程基本上可以算是比较不错的通用匹配了。(PS:我突然发现CODE_LITE把我的UBB转义了!!!晕,我只好自己转义了。。。)
Dim objRegExp,Matches,i,DC9_DOT_CN_MATCH
Dim aryMatch()
Redim Preserve aryMatch(0)
Set objRegExp=New RegExp
objRegExp.IgnoreCase =True
objRegExp.Global=True
objRegExp.Pattern="(?:\[[^\]]+\]([^\[]+)\[\/[^\]]+\])|(?:(?:href|src)=([^\s|^>]+)[""|>|\s\'])"
Set Matches = objRegExp.Execute("[img]2312.jpg[/img][img]2312.jpg[/img]hh[img]http://www.dc9.cn/cm/upload/2ed312.jpg[/img]<a href=""http://www.dc9.cn/ddd.jpg""></a> href=""http://www.dc9.cn/dccdd.jpg"">[IMG_RIGHT=400,300,title]upload/2assas.jpg[/IMG_RIGHT]<sctipt src="/UploadFiles/2021-04-02/">Dim TmpMatch
For i=0 to Matches.Count-1
Call InsertDataToArray(Matches(i).SubMatches(0),aryMatch)
Call InsertDataToArray(Matches(i).SubMatches(1),aryMatch)
Next
For i=0 to Ubound(aryMatch)
If Not IsNull(aryMatch(i)) And Trim(aryMatch(i))<>"" Then Response.write aryMatch(i)&"<br>"
Next
Function InsertDataToArray(Data,ByRef aryMatch)
If Trim(Data)<>"" Then
Data=Replace(Data,"'","")
Data=Replace(Data,"""","")
Data=Replace(Data,"\","/")
Data=Split(Data,"/")(Ubound(Split(Data,"/")))
Redim Preserve aryMatch(Ubound(aryMatch)+1)
DC9_DOT_CN_MATCH=False
For j=0 to Ubound(aryMatch)
If aryMatch(j)=Data Then DC9_DOT_CN_MATCH=True
Next
If Not DC9_DOT_CN_MATCH Then aryMatch(Ubound(aryMatch))=Data
End If
End Function
实际上,Z-Blog的话就匹配Upload就可以了(但是我为了省事,也为了更精确些,就干脆在上面的那个匹配上面加上了upload,所以看上去好像下面这个更复杂些,其实理论上应该下面这个简单些,毕竟有upload管着呢。。),也不用SPLit那个/.这么写就可以了:
Dim objRegExp,Matches,i,ZC_UPLOAD_MATCH
Dim aryMatch()
Redim Preserve aryMatch(0)
Set objRegExp=New RegExp
objRegExp.IgnoreCase =True
objRegExp.Global=True
objRegExp.Pattern="(?:\[[^\]]+\][^\[]*upload\/([^\[|^\\|^\/]+)\[\/[^\]]+\])|(?:(?:href|src)=""{0,1}[^\s|^""|^>|^']*upload\/([^\s|^>]+)[""|>|\s\'])"
Set Matches = objRegExp.Execute("[img]2312.jpg[/img][img]2312.jpg[/img]hh[img]http://www.dc9.cn/cm/upload/2ed312.jpg[/img]<a href=""http://www.dc9.cn/ddd.jpg""></a> href=""http://www.dc9.cn/dccdd.jpg"">[IMG_RIGHT=400,300,title]upload/2assas.jpg[/IMG_RIGHT]<sctipt src="/UploadFiles/2021-04-02/">Dim TmpMatch
For i=0 to Matches.Count-1
Call InsertDataToArray(Matches(i).SubMatches(0),aryMatch)
Call InsertDataToArray(Matches(i).SubMatches(1),aryMatch)
Next
For i=0 to Ubound(aryMatch)
If Not IsNull(aryMatch(i)) And Trim(aryMatch(i))<>"" Then Response.write aryMatch(i)&"<br>"
Next
Function InsertDataToArray(Data,ByRef aryMatch)
If Trim(Data)<>"" Then
Data=Replace(Data,"'","")
Data=Replace(Data,"""","")
Redim Preserve aryMatch(Ubound(aryMatch)+1)
ZC_UPLOAD_MATCH=False
For j=0 to Ubound(aryMatch)
If aryMatch(j)=Data Then ZC_UPLOAD_MATCH=True
Next
If Not ZC_UPLOAD_MATCH Then aryMatch(Ubound(aryMatch))=Data
End If
End Function
PS:最近正则又精进不少...
Dim objRegExp,Matches,i,DC9_DOT_CN_MATCH
Dim aryMatch()
Redim Preserve aryMatch(0)
Set objRegExp=New RegExp
objRegExp.IgnoreCase =True
objRegExp.Global=True
objRegExp.Pattern="(?:\[[^\]]+\]([^\[]+)\[\/[^\]]+\])|(?:(?:href|src)=([^\s|^>]+)[""|>|\s\'])"
Set Matches = objRegExp.Execute("[img]2312.jpg[/img][img]2312.jpg[/img]hh[img]http://www.dc9.cn/cm/upload/2ed312.jpg[/img]<a href=""http://www.dc9.cn/ddd.jpg""></a> href=""http://www.dc9.cn/dccdd.jpg"">[IMG_RIGHT=400,300,title]upload/2assas.jpg[/IMG_RIGHT]<sctipt src="/UploadFiles/2021-04-02/">Dim TmpMatch
For i=0 to Matches.Count-1
Call InsertDataToArray(Matches(i).SubMatches(0),aryMatch)
Call InsertDataToArray(Matches(i).SubMatches(1),aryMatch)
Next
For i=0 to Ubound(aryMatch)
If Not IsNull(aryMatch(i)) And Trim(aryMatch(i))<>"" Then Response.write aryMatch(i)&"<br>"
Next
Function InsertDataToArray(Data,ByRef aryMatch)
If Trim(Data)<>"" Then
Data=Replace(Data,"'","")
Data=Replace(Data,"""","")
Data=Replace(Data,"\","/")
Data=Split(Data,"/")(Ubound(Split(Data,"/")))
Redim Preserve aryMatch(Ubound(aryMatch)+1)
DC9_DOT_CN_MATCH=False
For j=0 to Ubound(aryMatch)
If aryMatch(j)=Data Then DC9_DOT_CN_MATCH=True
Next
If Not DC9_DOT_CN_MATCH Then aryMatch(Ubound(aryMatch))=Data
End If
End Function
实际上,Z-Blog的话就匹配Upload就可以了(但是我为了省事,也为了更精确些,就干脆在上面的那个匹配上面加上了upload,所以看上去好像下面这个更复杂些,其实理论上应该下面这个简单些,毕竟有upload管着呢。。),也不用SPLit那个/.这么写就可以了:
Dim objRegExp,Matches,i,ZC_UPLOAD_MATCH
Dim aryMatch()
Redim Preserve aryMatch(0)
Set objRegExp=New RegExp
objRegExp.IgnoreCase =True
objRegExp.Global=True
objRegExp.Pattern="(?:\[[^\]]+\][^\[]*upload\/([^\[|^\\|^\/]+)\[\/[^\]]+\])|(?:(?:href|src)=""{0,1}[^\s|^""|^>|^']*upload\/([^\s|^>]+)[""|>|\s\'])"
Set Matches = objRegExp.Execute("[img]2312.jpg[/img][img]2312.jpg[/img]hh[img]http://www.dc9.cn/cm/upload/2ed312.jpg[/img]<a href=""http://www.dc9.cn/ddd.jpg""></a> href=""http://www.dc9.cn/dccdd.jpg"">[IMG_RIGHT=400,300,title]upload/2assas.jpg[/IMG_RIGHT]<sctipt src="/UploadFiles/2021-04-02/">Dim TmpMatch
For i=0 to Matches.Count-1
Call InsertDataToArray(Matches(i).SubMatches(0),aryMatch)
Call InsertDataToArray(Matches(i).SubMatches(1),aryMatch)
Next
For i=0 to Ubound(aryMatch)
If Not IsNull(aryMatch(i)) And Trim(aryMatch(i))<>"" Then Response.write aryMatch(i)&"<br>"
Next
Function InsertDataToArray(Data,ByRef aryMatch)
If Trim(Data)<>"" Then
Data=Replace(Data,"'","")
Data=Replace(Data,"""","")
Redim Preserve aryMatch(Ubound(aryMatch)+1)
ZC_UPLOAD_MATCH=False
For j=0 to Ubound(aryMatch)
If aryMatch(j)=Data Then ZC_UPLOAD_MATCH=True
Next
If Not ZC_UPLOAD_MATCH Then aryMatch(Ubound(aryMatch))=Data
End If
End Function
PS:最近正则又精进不少...
标签:
正则表达式,数组
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“文件名 正则表达式提取方法”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。