LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan from string

Sometimes, it was very easy to use the format string.

Frequently, the format string was not reliable to me.

 

I want to obtain two or three floating numbers from a string.

"Series 1:      -0.02446      -0.02446  0.00031"

or "Series 2:     -0.10868                0.00046" 

 

For three numbers, I used "1:\s\s\s\s\s%s\s\s\s\s\s\s%s\s\s%s" as the format string.

1) Can you check my format string for 3 numbers?

2) How to prepare the regular expression for floating number? Is it inefficient to try with match pattern.vi for my purpose? 

 

Labmaster.

0 Kudos
Message 1 of 16
(8,221 Views)

Regular Expressions can be your friend.

 

Here I used a Search and Replace String (set to Regular Expression) to remove the series number.  The While Loop looks for a number, with or without a minus sign, and appends it to the Result array.

 

Read the Regexp like this:

  • look for a minus sign, or not (the question mark makes the minus sign optional)
  • followed by any number of digits (character class [\d]
  • followed by a decimal point, or not (the backslash excapes the special meaning of the dot in a Regexp)
  • followed by more digits
  • OR (the pipe is the boolean OR operator, the arguments on either side are in parentheses)
  • look for a minus sign, or not
  • followed by a decimal point
  • followed by digits

The first part of the search looks for numbers like -1.23, the second part finds numbers like -.123.

 

numbers from string.png

 

Example attached.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 2 of 16
(8,208 Views)

I did.  I really spelled "escapes" with an "x". Smiley Tongue

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 3 of 16
(8,188 Views)

Check this out. 🙂

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 16
(8,167 Views)

How do you extract initials?

 

Let's say you have a name:  Benjamin Roger Moore

and you want to get BRM

 

Here is how far I got:

 

Benjamin Moore

 

.+\s.

 

Any characters before the space and 1 character after:  Benjamin M

 

How do I pick the first & last characters?

 

Actually, where I am stuck is how do you add to the regular expression? 

 

regEx noob...

 

0 Kudos
Message 5 of 16
(8,013 Views)

Here is the basics. If you want to include punctuation and other stuff (like names with more than 4 names) that is left as an exercise for the user.Find Initials Regular Expression.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 6 of 16
(8,002 Views)

How do you get the three string outputs at the bottom?  I am using LV8.2.  I don't think there was any change since then..

 

Based on your regEx, I was on the right track, but missed out on the * operator for *\s*.

 

At least I'm learning...  😉

 

BTW, ignore the shaded Match Regular Expression.  I copied the code to Paint and it came out shaded...

 

0 Kudos
Message 7 of 16
(7,989 Views)

Just grab the bottom edge and drag down. Just like a build array or string concatenate. BTW, you will noticed the '?' in the middle of the regular expression to account for fewer than three names in the input name. If you needed this to work for much longer names I would probably build do the match in a loop to allow you to work for very long names.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 8 of 16
(7,981 Views)

It can also be done with a lookahead. The regex is a lot shorter but the down side is the use of a while loop.

Ben64

 

Extract Initials.png

0 Kudos
Message 9 of 16
(7,953 Views)

You seem to have a lookahead assertion which allows a match of 0 items, basically always true.  If my suspicion is correct, you can eliminate the assertion and make the regex even shorter (\b\w).

 

When I find myself facing a regex in a loop, I try to see if my old friend Search and Replace can help.

 

InitialsRegex.png

 

Message 10 of 16
(7,942 Views)