我正在试着根据1。学位2。多年的经验来匹配不同职位的经验水平。模式相当简单(例如:"BS/5“将是具有5年经验的理科学士。我也有一些条目遵循此方案,但在同一字符串中具有多个学位和经验水平(例如:"BS/5-MS/2"),它们被认为是等效的。我有一个基本函数,它可以匹配并查找子字符串模式,但是即使我已经将regexp对象的.Global属性设置为true,它也不会返回多个匹配。有什么想法吗?代码如下:
On Error Resume Next
ActiveWorkbook.VBProject.References.AddFromGuid "{3F4DACA7-160D-11D2-A8E9-00104B365C9F}", 5, 5
Dim theRegex As Object
Dim theString As String
Set theRegex = CreateObject("VBScript.RegExp")
With regex
.MultiLine = False
.Global = True
.IgnoreCase = False
End With
theRegex.Pattern = "([A-z][A-z][A-z]?/[0-9][0-9]?)"
theString = "MS/9-PhD/4"
Set MyMatches = theRegex.Execute(theString)
Debug.Print "SubMatches.Count: " & MyMatches.Item(0).SubMatches.Count
If MyMatches.Count <> 0 Then
With MyMatches
For myMatchCt = 0 To .Count - 1
Debug.Print "myMatchCt: " & myMatchCt
For subMtCt = 0 To .Item(subMtCt).SubMatches.Count - 1
Debug.Print "subMtCt: " & subMtCt
Debug.Print ("," & .Item(myMatchCt).SubMatches.Item(subMtCt))
Next
Next
End With
Else
Debug.Print "No Matches"
End If发布于 2013-04-18 22:40:55
尝试更改行With Regex
至
With theRegex
.MultiLine = False
.Global = True
.IgnoreCase = False
End With您的On Error resume next语句掩盖了这个错误。
https://stackoverflow.com/questions/16084909
复制相似问题