asp 正则表达式

str="[code]aaad[/code]sd343迪斯科舞[lee]sevvv[/lee]说到底是"
pt ="\[([a-z]+)\]([a-z]+)\[/(\1)\]"
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分大小写。
regEx.Global = True ' 设置全程可用性。
Set Matches = regEx.Execute(strng) ' 执行搜索。
For Each Match in Matches ' 遍历 Matches 集合。
RetStr = RetStr & Match.FirstIndex & "。匹配的长度为"
RetStr = RetStr & Match.Length &" " & "<br>"
RetStr = RetStr & Match.SubMatches(0) &" "& "<br>" 
RetStr = RetStr & Match.SubMatches(1)&" " & "<br>" 
RetStr = RetStr & Match.SubMatches(2)&" " & "<br>"
RetStr = RetStr & Match.value&" " & "<br>"
RetStr = RetStr &  "<br>--------------<br>"
Next
RegExpTest = RetStr
End Function

response.Write(RegExpTest(pt, str))

输出结果:
0。匹配的长度为17
code
aaad
code
[code]aaad[/code]

--------------
26。匹配的长度为16
lee
sevvv
lee
[lee]sevvv[/lee]

--------------

posted on 2011-03-10 15:56  woshilee  阅读(222)  评论(0)    收藏  举报

导航