Attribute VB_Name = "MatchesFound_bas" Option Explicit Public Function MatchesFound(ByVal RegExp_IN As String, ByVal GIM_Flags_IN As String, ByVal Input_IN As String) As String Application.Volatile On Error GoTo ErrorHandler MatchesFound = MatchesFoundEvaluate(RegExp_IN, Input_IN _ , InStr(1, GIM_Flags_IN, "G", vbTextCompare) _ , InStr(1, GIM_Flags_IN, "I", vbTextCompare) _ , InStr(1, GIM_Flags_IN, "M", vbTextCompare)) 'Debug.Print "MatchesFound=" & MatchesFound Exit Function ErrorHandler: MatchesFound = Err.Description End Function Private Function MatchesFoundEvaluate(ByVal RegExp_IN As String, ByVal Input_IN As String _ , ByVal Global_IN As Boolean, ByVal IgnoreCase_IN As Boolean, ByVal MultiLine_IN As Boolean) As String Application.Volatile On Error GoTo ErrorHandler Dim RegExp As RegExp RegExp_IN = Replace(RegExp_IN, vbLf, "") Set RegExp = New RegExp If RegExp_IN = "" Then MatchesFoundEvaluate = "Empty RegExp" Exit Function End If RegExp.Pattern = RegExp_IN RegExp.Global = Global_IN RegExp.IgnoreCase = IgnoreCase_IN RegExp.MultiLine = MultiLine_IN Dim Index As Long Index = 0 Dim Matches As MatchCollection 'Debug.Assert Input_IN <> "" Set Matches = RegExp.Execute(Input_IN) If Matches.Count = 0 Then MatchesFoundEvaluate = "No matches" Else Dim Match As Match Dim Delimiter As String For Each Match In Matches MatchesFoundEvaluate = MatchesFoundEvaluate & Delimiter _ & Index & ") " & Match.Value '& " [" & Match.FirstIndex & ", " & Match.Length & "]" Delimiter = vbLf 'When a regular expression is executed, ' zero or more submatches can result when subexpressions are enclosed in capturing parentheses. 'Each item in the SubMatches collection is the string found and captured by the regular expression. Dim SubMatch As Variant Dim SubIndex As Long SubIndex = 0 For Each SubMatch In Match.SubMatches MatchesFoundEvaluate = MatchesFoundEvaluate & Delimiter _ & Index & "." & SubIndex & ") " & SubMatch SubIndex = SubIndex + 1 Next SubMatch Index = Index + 1 Next Match End If Exit Function ErrorHandler: MatchesFoundEvaluate = Err.Description End Function