I'm running VBA (Excel 2003) and testing a positive lookbehind regex pattern. I run the function below but get the following error:
我正在运行VBA (excel2003)并测试regex模式的积极外观。我运行下面的函数,但得到以下错误:
Run-time error '5017': Method 'Execute' of object 'IRegExp2' failed
运行时错误'5017':方法'Execute'对象'IRegExp2'失败
I've also tried Set re = CreateObject("vbscrip.regexp")
but I get the same error. I've successfully tested some positive lookaheads and they work. It's just the lookbehind that is problematic. I've tested the patter below with Expresso and it worked fine. Is this a flavor problem peculiar to VBA?
我也尝试过Set re = CreateObject(“vbscript .regexp”),但是我得到了相同的错误。我已经成功地测试了一些正面的lookaheads,它们工作。这只是个问题。我已经用Expresso测试了下面的模式,效果很好。这是VBA特有的口味问题吗?
Function regexSearch(pattern As String, source As String) As String
Dim re As RegExp
Dim matches As MatchCollection
Dim match As match
'Create RegEx object
pattern = "(?<=a)b"
source = "cab"
Set re = New RegExp
re.Multiline = False
re.Global = True
re.IgnoreCase = False
re.pattern = pattern
'Execute
Set matches = re.Execute(source)
'Output
For Each match In matches
str = str & match & " "
Next match
regexSearch = str
End Function