Juggler_IN
Active Member
- Joined
- Nov 19, 2014
- Messages
- 349
- Office Version
- 2003 or older
- Platform
- Windows
I have a RegEx Time function that extracts time values from a string.
The code extracts values but misses out on the pm in the test string: Immediate Window ?Join(Time("ABCD 10:10:10 am to 20:10:10 pm EFGH")) outputs 10:10:10 am 20:10:10.
I am unable to figure out the edits.
The function:
The code extracts values but misses out on the pm in the test string: Immediate Window ?Join(Time("ABCD 10:10:10 am to 20:10:10 pm EFGH")) outputs 10:10:10 am 20:10:10.
I am unable to figure out the edits.
The function:
VBA Code:
Public Function Time(x As String)
Dim oRegex As Object
If oRegex Is Nothing Then
Set oRegex = CreateObject("VBScript.RegExp")
oRegex.Global = True
oRegex.Pattern = "\b(0?[0-9]|1[0-2]):[0-5]\d(:[0-5]\d)?\s?(AM|PM|am|pm)\b|\b([0-9]|[0-1]\d|2[0-3]):[0-5]\d(:[0-5]\d)?(?!:)"
End If
Time = Empty
If oRegex.Test(x) Then Time = Array(oRegex.Execute(x).Item(0).Value, oRegex.Execute(x).Item(1).Value)
End Function