Excel VBA的正则表达式正面观察问题

时间:2012-09-25 02:02:44

标签: regex excel vba

我正在运行VBA(Excel 2003)并测试一个积极的lookbehind正则表达式模式。我运行下面的函数,但得到以下错误:

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 In matches
   str = str & match & " "
Next match
regexSearch = str
End Function

1 个答案:

答案 0 :(得分:4)

特别是(因此)。

不支持lookbehind(负面或正面)