LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Match pattern search for string that starts with "x =" or "f ="

Solved!
Go to solution

Very quick question to bother you guys with. I want to be able to use the match pattern to parse the response from my device and see if the response contains either "x =" or "f =" with the white space in the middle. I then want to take everything after that and use it. Is that easy to do with Match Pattern, and what would that look like? In other words, is it just like any regex and how do I do I make the first character variable in regex? Thank you.

0 Kudos
Message 1 of 11
(3,065 Views)
Solution
Accepted by topic author crash_override

I'd say that "[xf]\s=" ought to do it.

[xf] matches any character between the square brackets.  Here it will match 'x' or 'f'

\s matches a space character

= matches an equals character

 

An alternate to cover upper and lower case as well as a variable # of spaces: "[XxFf]\s*="

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 11
(2,984 Views)
Solution
Accepted by topic author crash_override

The only change I would make to Kevin's pattern is "([xf])\s=" to capture the initial part so you can use that in a case diagram if you want different behaviour.

Message 3 of 11
(2,978 Views)

This is fairly simple, if you have any experience with strings, know how to use LabVIEW Help, understand how to use loops (and conditional indexing or concatenating tunnels) along with shift registers to "take apart" (or "parse") data.

 

Why don't you start by using one of the Pattern Matching routines in LabVIEW (read its Detailed Help for ... detailed help)?  If you attach some code (runnable VIs, please, no static pictures) showing what you are doing, and show the search string(s) you think would be useful, we can comment and help you with the one or two things you might have missed ...

 

Bob Schor

 

Message 4 of 11
(2,976 Views)

This is what I came up with, but it doesn't work correctly yet. I set match pattern to look for the '=' and then grab that because I know the response I'm looking for will always have that. The problem is when I get that value the switch case to determine whether it is a response with the '=' in it or not seems to just not display anything in the "Measurement 2" Indicator. Not sure why. Earlier displaying every response even with the switch case but it's supposed to be the output of match pattern.

0 Kudos
Message 5 of 11
(2,962 Views)

Your case diagram was obviously connected to a boolean originally, and now it is a string trying to match the values "True" or "False". Perhaps you should try changing "True" to "" (empty string) and remove Default Case,  and change  "False" to Default Case, to get started.

Message 6 of 11
(2,945 Views)

...... and get rid of the select statement.

0 Kudos
Message 7 of 11
(2,934 Views)
Solution
Accepted by topic author crash_override

Paul Davey's solution is nice (with the parentheses to capture the X,x,F or f) but note that you'll need to use Match Regular Expression rather than Match Pattern to be able to get sub-pattern matches.

Consider the handling of things that don't match your pattern...Consider the handling of things that don't match your pattern...


GCentral
Message 8 of 11
(2,785 Views)

Thank you all. I'm now using the regular expression and it works but only for the first instance of the loop. I will have to get back to guys when I figure that part out.

0 Kudos
Message 9 of 11
(2,767 Views)

Here are a few suggestions to help you write code that is easier for you (and us) to understand:

  • Try to keep the Error Line straight, no corners.
  • Try to keep all other wires "as straight as practical" (and hence parallel to the Error Line).
  • Make sure that wires never run "backwards", i.e. from right-to-left (unless you are writing in Arabic or Hebrew).
  • Do your best to get rid of blank spaces.  try to avoid having to scroll around.

You mention a problem with a loop in parsing your string.  I did not see this in the code you attached.

 

Bob Schor

Message 10 of 11
(2,744 Views)