Public Function IsolateInformation(ByVal AnyText As String, ByVal SearchPattern As String) As Variant
' Examples for Pattern
' Date 1/12/2022 - "\d{1,2}/\d{1,2}/\d{4}"
' Time 7:59:59 AM - "\d{1,2}:\d{2}:\d{2} [AP]M"
Static oRegEx As Object
Dim oMatchCollection As Object
Dim lCount As Long
Dim retArray() As Variant
Dim i As Long
If oRegEx Is Nothing Then Set oRegEx = CreateObject("VBScript.RegExp")
With oRegEx
.Pattern = SearchPattern
.IgnoreCase = True
.Global = True
Set oMatchCollection = .Execute(AnyText)
lCount = oMatchCollection.Count
ReDim retArray(lCount)
retArray(0) = lCount
For i = 1 To lCount
retArray(i) = oMatchCollection(i - 1)
Next
IsolateInformation = retArray
End With
End Function
Sub evaluate_IsolateInformation()
Const csText1 = "From 7:00:00 AM To 7:59:59 AM"
Const csText2 = "From 1/1/2021 To 1/31/2021"
Const csText3 = "Possible dates this week 1/2/2022 or 3/2/2022, or maybe next week on 8/2/2022"
Dim myArray As Variant
Dim i As Long
myArray = IsolateInformation(csText3, "\d{1,2}/\d{1,2}/\d{4}")
For i = 0 To UBound(myArray)
Debug.Print myArray(i)
Next
End Sub