I have a test file that has many lines, each line looks something like:
4:19 PM 5:15 PM this is some text blah blah
I need a regex that will pull the 2 times and assign them to a variable.
So basically i’m going to be looping through a text file, and extracting the time information from each line and adding up the difference between the two.
I need help with the regex.
This uses a slightly tweaked regex and adds the differences between dates as you mentioned:
Result: Total difference: 02:56:00
If you’re confident that your data is in the correct format you could make the regex very simple as follows:
If you don’t trust the data then you’ll probably want something more robust.