0

I have this form of string entry:

002  0000     A     C        00:00:20:01 00:00:31:23 00:01:29:24 00:01:41:21

From previous question I can capture it with:

Set re = New RegExp
re.Pattern = "C        (\d{2}:\d{2}:\d{2}:\d{2}) (\d{2}:\d{2}:\d{2}:\d{2})"
matches = re.Execute(prev)

Now I have 2 submatches that I need to perform arithmetic on.

How can I seperate out each submatch to a list of digit pairs seperated by ":" into a list(not sure of term?)?

These strings are timestamps that I want to decompose down to frame counts.

I expected to convert Timecode to 25 frames per second:

  1. 1st pair is hours to frame time base (25fps) 1 hour = 1*60*(60*25) = 9000
  2. 2nd pair is minutes to frame time base (25fps) 1 minute = 1*(60*25) = 1500
  3. 3rd pair is seconds to frame time base (25fps) 1 second = 1*25f

For example a submatch of 00:02:20:01 would convert to 3501 frames

Previous question for reference

EDIT Here's what I ended up with. I had to find the difference (datediff) between time values which returned an answer in "seconds", Then I convert this to time format with timeserial. But it appended with an AM/PM clock so I set the scripts region to Germany, which turns off the AM/PM suffix.

Option Explicit
'change system location to Germany, to simulate 24hour clock *no AM PM time
setlocale "de-de"

'TBA read whole data doc to grab the NameDetails and TC


    Dim TC
    'temporary data set, I will need to send each line to this search
    TC ="002  0000     A     C        00:00:20:01 00:00:23:23 00:01:29:24 00:01:41:21"

    'Define search terms for each timecode element *this is not a result yet
    Dim re1
    re1 =".*?"  'Non-greedy match on filler
    Dim re2
    re2 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"  'HourMinuteSec 1
    Dim re3
    re3 =".*?"  'Non-greedy match on filler
    Dim re4
    re4 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 2
    Dim re5
    re5 =".*?"  'Non-greedy match on filler
    Dim re6
    re6 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 3
    Dim re7
    re7 =".*?"  'Non-greedy match on filler
    Dim re8
    re8 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 4

    'add timecode search terms to a search pattern
    Dim r
    Set r = New RegExp
    r.Pattern = re1+re2+re3+re4+re5+re6+re7+re8
    r.IgnoreCase = True

    Dim m, timeDur, ts, Timeofday
    Set m = r.Execute(TC)
    'loop through timecodes to find duration between first 2 entries
    If m.Item(0).SubMatches.Count > 0 Then
        Dim time1
        time1=m.Item(0).SubMatches.Item(0)
        Dim time2
        time2=m.Item(0).SubMatches.Item(1)
        Dim time3
        time3=m.Item(0).SubMatches.Item(2)
        Dim time4
        time4=m.Item(0).SubMatches.Item(3)

        'find duration/difference between first 2 times, in seconds
        timeDur=datediff("s", time1, time2)
        'format result to a serial time format eg. 00:00:00
        ts = TimeSerial(0, 0, timeDur)
        'print duration result, will need to append track info and repeat. Then save to file
        MsgBox (ts)

    End If
3pointedit
  • 117
  • 7
  • 1
    You could [`Split`](https://msdn.microsoft.com/en-us/library/0764e5w5) the extracted substrings at colons, or extract each number as a separate substring (`(\d{2}):(\d{2}):(\d{2}):...`). Use [`CInt`](https://msdn.microsoft.com/en-us/library/fctcwhw9) to convert the number strings to actual numbers. – Ansgar Wiechers May 15 '18 at 18:21

1 Answers1

1

So, ultimately I'm guessing you want to match on regex "time", and use the VBScript function "split"... Here is an example that might help you:

Dim txt
txt ="002  0000     A     C        00:00:20:01 00:00:31:23 00:01:29:24 00:01:41:21"

Dim re1
re1 =".*?"  'Non-greedy match on filler
Dim re2
re2 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-  9])?(?:\s?(?:am|AM|pm|PM))?)"  'HourMinuteSec 1
Dim re3
re3 =".*?"  'Non-greedy match on filler
Dim re4
re4 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 2
Dim re5
re5 =".*?"  'Non-greedy match on filler
Dim re6
re6 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 3
Dim re7
re7 =".*?"  'Non-greedy match on filler
Dim re8
re8 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 4

Dim r
Set r = New RegExp
r.Pattern = re1+re2+re3+re4+re5+re6+re7+re8
r.IgnoreCase = True
Dim m
Set m = r.Execute(txt)
If m.Item(0).SubMatches.Count > 0 Then
    Dim time1
    time1=m.Item(0).SubMatches.Item(0)
    Dim time2
    time2=m.Item(0).SubMatches.Item(1)
    Dim time3
    time3=m.Item(0).SubMatches.Item(2)
    Dim time4
    time4=m.Item(0).SubMatches.Item(3)
    Response.Write("("+Replace(time1,"<","&lt;")+")"+"("+Replace(time2,"<","&lt;")+")"+"("+Replace(time3,"<","&lt;")+")"+"("+Replace(time4,"<","&lt;")+")"+"")
End If
Nathan Rice
  • 3,091
  • 1
  • 20
  • 30
  • Thanks this is really helpful. Can I ask dumb question? I don't understand how "re2" works to search so I'm not sure how to loop to the second timestamp so i can perform a subtraction between them? How could I use a variable in "re2" to bump along to the next value? – 3pointedit May 16 '18 at 08:23
  • I updated the answer to help you see a little more. Each of those regex's grabs the appropriate timestamp. – Nathan Rice May 16 '18 at 16:12
  • 1
    Oh wow, thats so helpful, I really couldn't find anything that made this clearer. Most regexp demos showed word sorting only. – 3pointedit May 16 '18 at 21:11
  • Just pointing out that Response.write didn't work so I replaced it with MsgBox. Not sure why? – 3pointedit May 21 '18 at 03:28
  • The result seems to be the same as the source string (with frames removed). But I cannot perform a math function to find the difference between time1 and time2 for example? The original question suggests that I need to perform arithmetic as well as display result? – 3pointedit May 21 '18 at 03:31
  • Ok I have added a DateDiff functionto find the duration between time stamps, which returns seconds. Then I reformat with serialized time to return a date formated time value. I will add it to the question and accept your answer. – 3pointedit May 21 '18 at 05:34