annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

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
Messaggio 1 di 16
9.647Visualizzazioni

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

Messaggio 2 di 16
9.634Visualizzazioni

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

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
Messaggio 3 di 16
9.614Visualizzazioni

Check this out. 🙂

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
Messaggio 4 di 16
9.593Visualizzazioni

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
Messaggio 5 di 16
9.439Visualizzazioni

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
Messaggio 6 di 16
9.428Visualizzazioni

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
Messaggio 7 di 16
9.415Visualizzazioni

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
Messaggio 8 di 16
9.407Visualizzazioni

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
Messaggio 9 di 16
9.379Visualizzazioni

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

 

Messaggio 10 di 16
9.368Visualizzazioni