Function ExtractBetweenDelimitersRegex(ByVal InputString As String, ByVal StartDelimiter As String, ByVal EndDelimiter As String) As Collection
Dim Regex As Object
Dim Matches As Object
Dim Match As Object
Dim Results As New Collection
Dim Pattern As String
' Build the regex pattern dynamically
Pattern = StartDelimiter & "(.*?)" & EndDelimiter
' Create the regex object
Set Regex = CreateObject("VBScript.RegExp")
With Regex
.Pattern = Pattern
.Global = True ' Ensure it matches all occurrences
.IgnoreCase = True ' Optional: make case-insensitive
End With
' Execute the regex
Set Matches = Regex.Execute(InputString)
' Loop through matches and extract the captured groups
For Each Match In Matches
Results.Add Match.SubMatches(0) ' Add the captured group to the collection
Next Match
' Return the collection
Set ExtractBetweenDelimitersRegex = Results
End Function