07-30-2016 09:07 AM
I felt some complications whenever I used Match Pattern.vi.
For example, my string is..
16:04:57] Written data (COM2)
53 49 4e 4b 20 0d 0a YAH ..
[20/07/2016 16:05:02] Read data (COM2)
72 65 61 64 79 0d 0a ready..
[20/07/2016 16:05:12] Written data (COM2)
53 49 0d 0a XI..
[20/07/2016 16:05:22] Read data (COM2)
53 20 20 20 20 20 2d 30 2e X.. 2222
[20/07/2016 16:05:32] Written data (COM2)
53 49 0d 0a XI..
[20/07/2016 16:05:48] Read data (COM2)
53 20 20 20 20 20 2d 30 2e X.. 1111
1) I want to find the latest time string, 16:05:48 in the end of string. How can I set up the regular expression?
[0-9]+:[0-9]+:[0-9]+$ didn't work.
2) How can I find "16:05:48 ..... X.."?
".*" is useful in finding the longest string but in my case, shortest string between timestamp and a string.
labmaster.
07-30-2016 10:01 AM
To find the last such time reverse the string, find the first "]" then find the first space after. Reverse the resulting substring and you have your timestamp.
Lynn
07-30-2016 02:24 PM
Good call, Lynn. I have a colleague who takes single PNG images once a second for up to an hour, and instead of naming the files "Expt 23, Frame 1", he calls it "Expt20160105_114811.65", where all the numbers are a string representation of the acquisition Time Stamp. To convert it to a more "user-friendly" form (the Absolute Time is irrelevant -- the Frame order is what is important), I wanted to parse this into a cluster of Name, Date, and Time, and found the Reverse String and Parse was the way to go. [Needless to say, the Real Story is that he had two such formats, depending on whether the data were taken with "Version 1" or "Version 2" code, and I wanted to, and did, write a single parser that accepted both styles].
Bob Schor
07-30-2016 08:12 PM - edited 07-30-2016 08:13 PM
If you felt you might need all the information eventually, you could parse out each packet of information as submatches in a "Match Regular Expression" inside a while loop to generate an array of data. Then, for your purpose, take the last element and play with it.
The benefit is that now you have a parser that you can use when you inevitably have to process all that data.