5

I'm running VBA (Excel 2003) and testing a positive lookbehind regex pattern. I run the function below but get the following error:

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

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?

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
brettdj
  • 54,857
  • 16
  • 114
  • 177
TSB
  • 141
  • 3
  • 12

1 Answers1

6

It is particular to (and hence ).

doesn't support lookbehind (negative or positive)

brettdj
  • 54,857
  • 16
  • 114
  • 177