LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

regular expression in match pattern.vi

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.

0 Kudos
Message 1 of 4
(3,371 Views)

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

 

Match.png

0 Kudos
Message 2 of 4
(3,351 Views)

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

0 Kudos
Message 3 of 4
(3,333 Views)

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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 4
(3,323 Views)