LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parse MFC Regular Expression Help

I am trying to parse serial ASCII output from an MFC (Mass Flow Controller) using regular expressions, but I am having some trouble.  Here's an example string:

F +014.49 +020.93 +0000.0 +0000.0 0000.0     Air

where:
F            : Id of MFC - can only be A-Z
+014.49 : Pressure
+020.93 : Temperature
+0000.0 : Flow
+0000.0 : Mass Actual
0000.0   : Mass Set Point
Air         : Gas Type - this is optional as older MFCs don't have this

I am using this regular expression, although I'm not quite sure why it's picking up more values than it is:

[A-Z] [+-]+\d.+\d ?\w



I've attached the VI.  Can anyone point me in the right direction here?  I would like to be able to validate the string and also pick out each piece.  Can this be done with a single regular expression or do I need multiple calls?

Thanks


Message Edited by Derek Price on 01-09-2008 03:56 PM
Download All
0 Kudos
Message 1 of 9
(3,569 Views)


Derek Price wrote:

I am using this regular expression, although I'm not quite sure why it's picking up more values than it is:

Message Edited by Derek Price on 01-09-2008 03:56 PM

I don't understand what you mean by "it's picking up more values than it is".
 
If you meant "it's picking up more values than it should", then the reason is that you have a ".+" in the middle of your regular expression.
Reg
S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
0 Kudos
Message 2 of 9
(3,560 Views)



I would like to be able to validate the string and also pick out each piece.  Can this be done with a single regular expression or do I need multiple calls?

Message Edited by Derek Price on 01-09-2008 03:56 PM

If I had to use the match regular expression function, I would use one regular expression to validate the string, followed by regular expressions to pick out each piece. 
 
Also, the scan string and match pattern functions might be faster and easier to use.  Let me see if I can quickly put together an example.
 
 
S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
0 Kudos
Message 3 of 9
(3,556 Views)
You could instead, simply use the Spreadsheet String to Array to convert the string you read to an array of strings which you can then simply pick off the individual components. That, to me, seems to be a whole lot easier. You could even do a blanket conversion to a number using the string conversion functions, and pick off the numbers you want. See attached mod.
Message 4 of 9
(3,554 Views)
Here's an example that uses the "Scan From String.vi" to extract all the fields.  Pass in the format string of   "%1s %f %f %f %f %f %s".
 
However, I would still use the match regular expression.vi to validate the string before calling the scan from string to extract all the data.  That way I can weed out strings that have errors in them that would not be caught by the Scan from string.vi (such as field width errors for numerics).
 
S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
Message 5 of 9
(3,553 Views)
You could also..

Darn! Beaten to the punch by SG.


Message Edited by smercurio_fc on 01-09-2008 05:12 PM
Message 6 of 9
(3,547 Views)
Thanks for all the suggestions!  I am currently using the OpenG VIs "String to 1D Array" and "Filter 1D Arry" (to remove empty array items) similar to smercurio_fc's "Spreadsheet String to Array" solution.  I like SG's solution of using "Scan From String", but I'm not sure how to handle the case where the optional gas field at the end is missing as this causes an error.  I would still like to use a regular expression to validate the string, but I am unsure of how to explicitly have each field parsed as opposed to my greedy regular expression that SG pointed out.  Do you have any suggestions on how to fix my regular expression?

Thanks!
0 Kudos
Message 7 of 9
(3,518 Views)

The regular expression you construct would depend on the exact format of the string you expect.

For instance, one of your fields there is "0000.0"

What happens when a different number comes in?  Would 12.34 be passed in as 12.34 or 012.34 or 12.340?  How about the number 12345.6?  Would be be passed in as 12345.6 or just 12345

S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
0 Kudos
Message 8 of 9
(3,506 Views)

The regular expression you construct would depend on the exact format of the string you expect.

For instance, one of your fields there is "0000.0"

What happens when a different number comes in?  Would 12.34 be passed in as 12.34 or 012.34 or 12.340?  How about the number 12345.6?  Would it be passed in as 12345.6 or just 12345 (since your field width seems to be 5 digits with a decimal point).  Or is field size irrelevant as long as the fields are separated by a space character.  For each of these cases, the regular expression would be different.

For each of the above cases, the rules are different and under ideal circumstances you would use a regular expression that validates it perfectly.  For perfect validation, you need 2 things to simultaneously occur:

1.  screening out of all possible false matches, and

2.  allowing of all possible true matches. 

So, the question for you is: what are the rules that govern your source string?

Regarding the last field being blank, you could use a format string of %1s %f %f %f %f %f and then use the offset past match to extract the last field.  But you may not need to do this since Mercurio's method works well too.  5 stars to Mercurio for showing me a different way to do it.

Regards,



Message Edited by S G on 01-10-2008 12:03 PM
S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
Message 9 of 9
(3,503 Views)