' 设置 Initialize 事件。 Private Sub Class_Initialize myGlobal = True myIgnoreCase = True End Sub
Property Let Global(g) Dim regEx ' 建立变量。 Set regEx = New RegExp ' 建立正则表达式。 regEx.Pattern = "True|False|1|0" ' 设置模式。 regEx.IgnoreCase = True ' 设置是否区分大小写。 If regEx.Test(CStr(g)) Then myGlobal = g Else Call Halt("无效Global参数配置") End If End Property
Property Get Global() Global = myGlobal End Property
Property Let IgnoreCase(c) Dim regEx Set regEx = New RegExp regEx.Pattern = "True|False|1|0" regEx.IgnoreCase = True If regEx.Test(CStr(c)) Then myIgnoreCase = c Else Call Halt("无效IgnoreCase参数配置") End If End Property
Property Get IgnoreCase() IgnoreCase = myIgnoreCase End Property
'解析所有HTML标记的函数 Public Function Parse(input) Parse = "<table border=1 width=50% align=center>" & vbCrLf Dim regEx , regVal , match , i
Set regEx = New RegExp regEx.Pattern = "<([a-z]\w*)(?:.*?)>(.*)<\/\1>" regEx.Global = myGlobal regEx.IgnoreCase = myIgnoreCase
Set regVal = regEx.Execute(Trim(input)) If regVal.Count > 0 Then '如果发现匹配元素 Parse = Parse & "<caption>发现" & regVal.Count & "个HTML标记</caption>" & vbCrLf Parse = Parse & "<tr align=center><th>编号</th><th>匹配标记<th>匹配显示</th></tr>" & vbCrLf For i=0 To regVal.Count-1 Set match = regVal(i) Parse = Parse & "<tr align=center>" & vbCrLf Parse = Parse & "<td>" & i+1 & "</td><td>" & match.SubMatches(0) & "</td><td>" & match & "</td>" & vbCrLf &nbs