文件名 正则表达式提取方法
文件名 正则表达式提取方法
发布时间:2016-12-29 来源:查字典编辑
摘要:下面这段子程基本上可以算是比较不错的通用匹配了。(PS:我突然发现CODE_LITE把我的UBB转义了!!!晕,我只好自己转义了。。。)Di...

下面这段子程基本上可以算是比较不错的通用匹配了。(PS:我突然发现CODE_LITE把我的UBB转义了!!!晕,我只好自己转义了。。。)

DimobjRegExp,Matches,i,DC9_DOT_CN_MATCH

DimaryMatch()

RedimPreservearyMatch(0)

SetobjRegExp=NewRegExp

objRegExp.IgnoreCase=True

objRegExp.Global=True

objRegExp.Pattern="(?:[[^]]+]([^[]+)[/[^]]+])|(?:(?:href|src)=([^s|^>]+)[""|>|s'])"

SetMatches=objRegExp.Execute("[img]2312.jpg[/img][img]2312.jpg[/img]hh[img]http://www.dc9.cn/cm/upload/2ed312.jpg[/img]<ahref=""http://www.dc9.cn/ddd.jpg""></a>href=""http://www.dc9.cn/dccdd.jpg"">[IMG_RIGHT=400,300,title]upload/2assas.jpg[/IMG_RIGHT]<sctiptsrc=""http://www.dc9.cn/upload/sss.jpg""")

DimTmpMatch

Fori=0toMatches.Count-1

CallInsertDataToArray(Matches(i).SubMatches(0),aryMatch)

CallInsertDataToArray(Matches(i).SubMatches(1),aryMatch)

Next

Fori=0toUbound(aryMatch)

IfNotIsNull(aryMatch(i))AndTrim(aryMatch(i))<>""ThenResponse.writearyMatch(i)&"<br>"

Next

FunctionInsertDataToArray(Data,ByRefaryMatch)

IfTrim(Data)<>""Then

Data=Replace(Data,"'","")

Data=Replace(Data,"""","")

Data=Replace(Data,"","/")

Data=Split(Data,"/")(Ubound(Split(Data,"/")))

RedimPreservearyMatch(Ubound(aryMatch)+1)

DC9_DOT_CN_MATCH=False

Forj=0toUbound(aryMatch)

IfaryMatch(j)=DataThenDC9_DOT_CN_MATCH=True

Next

IfNotDC9_DOT_CN_MATCHThenaryMatch(Ubound(aryMatch))=Data

EndIf

EndFunction

实际上,Z-Blog的话就匹配Upload就可以了(但是我为了省事,也为了更精确些,就干脆在上面的那个匹配上面加上了upload,所以看上去好像下面这个更复杂些,其实理论上应该下面这个简单些,毕竟有upload管着呢。。),也不用SPLit那个/.这么写就可以了:

DimobjRegExp,Matches,i,ZC_UPLOAD_MATCH

DimaryMatch()

RedimPreservearyMatch(0)

SetobjRegExp=NewRegExp

objRegExp.IgnoreCase=True

objRegExp.Global=True

objRegExp.Pattern="(?:[[^]]+][^[]*upload/([^[|^|^/]+)[/[^]]+])|(?:(?:href|src)=""{0,1}[^s|^""|^>|^']*upload/([^s|^>]+)[""|>|s'])"

SetMatches=objRegExp.Execute("[img]2312.jpg[/img][img]2312.jpg[/img]hh[img]http://www.dc9.cn/cm/upload/2ed312.jpg[/img]<ahref=""http://www.dc9.cn/ddd.jpg""></a>href=""http://www.dc9.cn/dccdd.jpg"">[IMG_RIGHT=400,300,title]upload/2assas.jpg[/IMG_RIGHT]<sctiptsrc=""http://www.dc9.cn/upload/sss.jpg""src=http://www.dc9.cn/upload/sasds.jpg'>")

DimTmpMatch

Fori=0toMatches.Count-1

CallInsertDataToArray(Matches(i).SubMatches(0),aryMatch)

CallInsertDataToArray(Matches(i).SubMatches(1),aryMatch)

Next

Fori=0toUbound(aryMatch)

IfNotIsNull(aryMatch(i))AndTrim(aryMatch(i))<>""ThenResponse.writearyMatch(i)&"<br>"

Next

FunctionInsertDataToArray(Data,ByRefaryMatch)

IfTrim(Data)<>""Then

Data=Replace(Data,"'","")

Data=Replace(Data,"""","")

RedimPreservearyMatch(Ubound(aryMatch)+1)

ZC_UPLOAD_MATCH=False

Forj=0toUbound(aryMatch)

IfaryMatch(j)=DataThenZC_UPLOAD_MATCH=True

Next

IfNotZC_UPLOAD_MATCHThenaryMatch(Ubound(aryMatch))=Data

EndIf

EndFunction

PS:最近正则又精进不少...

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新ASP教程学习
热门ASP教程学习
编程开发子分类