我正在运行 VBA (Excel 2003) 并测试正向后视正则表达式模式。我运行下面的函数但收到以下错误:
Run-time error '5017': Method 'Execute' of object 'IRegExp2' failed
我也试过,
Set re = CreateObject("vbscrip.regexp")
但我得到同样的错误。我已经成功地测试了一些积极的前瞻,并且它们有效。只是后面的问题是有问题的。我已经用 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 …Run Code Online (Sandbox Code Playgroud)