1

I am trying to search for multiple strings in a text log alltogether with the following pattern:

s(n)KEY: some data    
s(n)Measurement: some data    
s(n)Units: some data

Where s(n) is the number of spaces that varies. KEY will change at every iteration in the loop as it comes from the .ini file. As an example see the following snippet the of log:

   WHITE On Axis Lum_010      OPTICAL_TEST_01      some.seq
   WHITE On Axis Lum_010      Failed

      Bezel1 Luminance-Light Source: Passed
           Measurement:              148.41
           Units:                    fc

      WHITE On Axis Lum_010:         Failed
           Measurement:              197.5
           Units:                    fL

In this case, I only want to detect when the key (WHITE On Axis Lum_010) appears along with Measurement and I don't want to detect if it appears anywhere else in the log. My ultimate goal is to get the measurement and unit data from file.

Any help will be greatly appreciated. Thank you, Rav.

kosist
  • 1,784
  • 2
  • 13
  • 23
Rav
  • 31
  • 2

2 Answers2

3

I'd do it similar to Salome, using regular expressions. Since those are a little tricky, I have a test VI for them:

enter image description here

The RegEx is:

^\s{2}(.*?):\s*(\S*)\n\s*Measurement:\s*(\S*)\n\s*Units:\s*(\S*)

and means:

^             Find a beginning of a line
\s{2}         followed by exactly two whitespaces
(.*?)         followed by multible characters
:             followed by a ':'
\s*           followed by several whitespaces
(\S*)         followed by several non-whitespaces
\n            followed by a newLine
\s*           followed by several whitespaces
Measurement:  followed by this string
\s*           followed by several whitespaces
(\S*)         followed by several non-whitespaces
\n            followed by a newLine
... and the same for the 'Unit'

The parentheses denote groups, and allow to easily collect the interesting parts of the string. The RegEx string might need more tuning if the format of the data is not as expected, but this is a starting point.

To find more data in your string, put this in a while loop and use a shift register to feed the offset past match into the offset of the next iteration, and stop if it's =-1.

sweber
  • 2,746
  • 2
  • 13
  • 21
1

It's easier to search through and to implement. LabVIEW also has VIs to create and manage JSONs. Alternatively, you could use Regular Expressions in a while-loop to look if it exists in your log, maybe something like this:

WHITE On Axis Lum_010:(\s)*((Failed)|(Pass))\n(\s)+Measurement:(\s)*[0-9]*((\.)[0-9]*){0,1}\n(\s)*Units:\s*\w*

Then you can split the string or pick lines and take the information. But I would not recommend that, as it is impractical to change and not useful if you want to use the code for other keys. I hope it helps you :)

Salome
  • 221
  • 1
  • 7
  • 1
    Do you need the text log as a string or could you use JSON? I would add a comment above, but I can't do it yet :) – Salome Feb 26 '19 at 11:23