|
很久没看正则了,似乎慢慢遗忘了,今天复习下正则中两个对象的5个属性,高手绕过,纯属扫盲
'1、matches集合的count、item属性
Sub matches()
Dim reg As Object
Dim s As String
Dim i As Byte
Dim matches As Object
Set reg = CreateObject("vbscript.regexp")
s = "a25b31c67d4e"
With reg
.Global = True
.Pattern = "\d+"
Set matches = .Execute(s)
End With
MsgBox "匹配结果集合中元素个数为:" & matches.Count 'count属性
For i = 1 To matches.Count
MsgBox "matches集合中第" & i & "个元素为:" & matches.Item(i - 1) 'item属性
Next
End Sub
'2、match 对象firstindex属性、length属性、value属性
Sub match()
Dim reg As Object
Dim s As String
Dim i As Byte
Dim match As Object, matches As Object
Set reg = CreateObject("vbscript.regexp")
s = "a11b22c32d43e"
i = 1
With reg
.Global = True
.Pattern = "\d+"
Set matches = .Execute(s)
End With
For Each match In matches
MsgBox "matches集合中第" & i & "个元素在字符串中" & vbCrLf _
& "位置:" & match.firstindex & vbCrLf _
& "长度为:" & match.Length & vbCrLf _
& "值为:" & match.Value
i = i + 1
Next
End Sub
2009年9月2日,前行的路上,不要忘记回头望望,为了走的更稳!
[ 本帖最后由 taller 于 2009-9-5 02:24 编辑 ] |
评分
-
1
查看全部评分
-
|