When I was programming the ZBlog upload module today, I needed to use a subroutine to extract the file names in the article. At first I complicated the problem and matched all possible file names. Not only did I write a long list of regular expressions, but also Split below. After working on it for a long time, I suddenly discovered that all the uploaded files of Z-Blog were stored in upload, and so many complicated matches were written in vain. . . Hey, it can't be wasted. It's better to post it in case any brother needs it in the future~~
The following sub-process can basically be regarded as a relatively good universal matching. (PS: I suddenly discovered that CODE_LITE had escaped my UBB!!! Dizzy, I had to escape it myself...)
-------------------------------------------------- ----------------------------------
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][/img]<a href="" src="" 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
------------------------------------------------ --------------------------------
Actually, for Z-Blog, it just needs to match Upload (but to save trouble, I , and in order to be more accurate, I simply added upload to the above match, so it seems that the following one is more complicated. In fact, the following one should be simpler in theory. After all, upload is in charge.) Just write the SPLit /. like this:
-------------------------------------------------- ----------------------------------
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][/img]<a href="" src="" 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
Source: http://www.dc9.cn/post/279.html