选择显示字体大小

正则表达式结合数组提取文章中的文件名

今天编zblog上传模块的时候,需要用到一个提取文章中文件名的子程,开始我把问题想复杂了,匹配了所有可能的文件名,不仅正则表达式写了一大串,而且下面还split了半天,后来我突然发现z-blog的上传文件都存在upload下,白写了那么多复杂的匹配。。。哎,不能浪费掉啊,还是贴上来万一哪个兄弟以后需要也好拿去用~~

下面这段子程基本上可以算是比较不错的通用匹配了。(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="(?:\[[^\]]+\]([^\[]+)\[\/[^\]]+\])(?:(?:hrefsrc)=([^\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=""[img_right=400,300,title]upload/2assas.jpg[/img_right]http://www.dc9.cn/dccdd.jpg"">[img_right=400,300,title]upload/2assas.jpg[/img_right]<sctipt src=""http://www.dc9.cn/upload/sss.jpg""")
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\/([^\[^\\^\/]+)\[\/[^\]]+\])(?:(?:hrefsrc)=""{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=""[img_right=400,300,title]upload/2assas.jpg[/img_right]http://www.dc9.cn/dccdd.jpg"">[img_right=400,300,title]upload/2assas.jpg[/img_right]<sctipt src=""http://www.dc9.cn/upload/sss.jpg"" src=http://www.dc9.cn/upload/sasds.jpg>")
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

       
出处:http://www.dc9.cn/post/279.html

 


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons