The following code is what ive come up with so far. I have also set the reference for regular expression 5.5.
以下代码是我到目前为止所提出的。我还为正则表达式5.5设置了引用。
However the match value does not show at all, am I missing something here??
但是匹配值根本没有显示,我在这里遗漏了什么?
Public Sub check()
Dim wb As Workbook
Set wb = ThisWorkbook
'Prepare a regular expression object
Dim myRegExp As New VBScript_RegExp_55.RegExp
Dim myMatches As MatchCollection
Dim myMatch As match
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "^\d{6,8}-[SFTG]\d{7}[A-Z]-([^-]+)$"
Set myRegExp = CreateObject("vbscript.regexp")
cellValue = CStr(wb.Worksheets(1).Cells(2, 4).Value)
'123456-S1234567F-Scholarship Form
If myRegExp.Test(cellValue) Then
Set myMatches = myRegExp.Execute(cellValue)
For Each myMatch In myMatches
MsgBox (myMatch.Value)
Next
Else
End If
End Sub
1 个解决方案
#1
1
Removing the following line
删除以下行
Set myRegExp = CreateObject("vbscript.regexp")
seems to solve the issue.
似乎解决了这个问题。
I guess that's because all your initialization statements are gone when you assign myRegExp
to a new object
我想这是因为当你将myRegExp分配给一个新对象时,所有的初始化语句都消失了
#1
1
Removing the following line
删除以下行
Set myRegExp = CreateObject("vbscript.regexp")
seems to solve the issue.
似乎解决了这个问题。
I guess that's because all your initialization statements are gone when you assign myRegExp
to a new object
我想这是因为当你将myRegExp分配给一个新对象时,所有的初始化语句都消失了