日期:2014-05-16  浏览次数:20886 次

来个大神帮忙解决下正则表达式应用
我想弄个模版标签,可是一直弄不出来。。研究了好几天就知道用For Each Match In Matches可以解决,可就是研究不出来。。原来做UBB代码如下

function ubbcode(str)
if IsNull(str) then exit function
str=trim(str)
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
if instr(1,str,"[view_",1)>0 then
re.pattern="(\[view_(.[^\[]*)_(.[^\[]*)_(.[^\[]*)_(.[^\[]*)_(.[^\[]*)\])"
dim ar1,ar2,ar3,ar4,ar5
ar1=re.Replace(str,"$2")
ar2=re.Replace(str,"$3")
ar3=re.Replace(str,"$4")
ar4=re.Replace(str,"$5")
ar5=re.Replace(str,"$6")
if ar1="" or Isnumeric(ar1)=False then ar1=0
if ar2="" or Isnumeric(ar2)=False then ar2=0
if ar3="" or Isnumeric(ar3)=False then ar3=0
if ar4="" or Isnumeric(ar4)=False then ar4=0
ar1=abs(ar1)
ar2=abs(ar2)
ar3=abs(ar3)
ar4=abs(ar4)
ar5=abs(ar5)
str = re.Replace(str,GetSubStr(ar1,ar2,ar3,ar4,ar5))
end if
set re=Nothing
ubbcode=str
end function
function GetSubStr(ar1,ar2,ar3,ar4,ar5)
cid=ar1
num=ar2
lx=ar3
fl=ar4
br=ar5
If lx="1" Then tiaoj="by id desc"
If lx="2" Then tiaoj="by 点击 desc"
If lx="3" Then tiaoj="by NEWID()"
if cid<>0 then
gettest="where 显示=0 and 分类 in ("&cid&")"
Else
gettest="where 显示=0"
End If 
set rs8= server.createobject("adodb.recordset")
          rs8.open"select top "&num&" * from 列表 "&gettest&" order "&tiaoj&"",conn,1,1
           while not rs8.EOF
tuname=rs8(2)
tudizhi=rs8(3)
tudizhi1=rs8(7)
tudizhi2=rs8(8)
if left(tudizhi,4)="img/" Then tudizhi=wangzhanurl&tudizhi
if left(tudizhi1,4)="img/" Then tudizhi1=wangzhanurl&tudizhi1
if left(tudizhi2,4)="img/" Then tudizhi2=wangzhanurl&tudizhi2
tuname=replace(tuname,"&","")
if len(tuname) > 3 Then tuname=left(tuname,4)&".."
If fl="1" Then response.write"<a href='article.asp?id="&rs8(0)&"&amp;v="&v&"'>"&tuname&"</a>"
If fl="2" Then response.write"<a href='article.asp?id="&rs8(0)&"&amp;v="&v&"'><img src='"&tudizhi&"' alt='"&tuname&"'/></a>"
If fl="3" Then response.write"<a href='article.asp?id="&rs8(0)&"&amp;v="&v&"'><img src='"&tudizhi1&"' alt='"&tuname&"'/></a>"
If fl="4" Then response.write"<a href='article.asp?id="&rs8(0)&"&amp;v="&v&"'><img src='"&tudizhi2&"' alt='"&tuname&"'/></a>"
   If br="1" Then response.write"<br/>"
  rs8.MoveNext
  wend
                rs8.close
        set rs8=nothing
end function 

我想把这个用
Set Matches = regEx.Execute(str)
For Each Match In Matches
这样的方式表达出来该如何写代码呢?

------解决方案----