2012-09-25 99 views
3

我正在運行VBA(Excel 2003)並測試了正向lookbehind正則表達式模式。我運行下面的功能,但得到以下錯誤:正則表達式Excel Excel VBA

Run-time error '5017': Method 'Execute' of object 'IRegExp2' failed

我也試過 Set re = CreateObject("vbscrip.regexp")
,但我得到了同樣的錯誤。我已經成功測試了一些積極的lookahead,他們的工作。這只是背後的問題。我已經用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 
+0

你有沒有找到解決類似的問題?我不知道如何做這項工作。 – Yaegz

回答