LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Regular Expression

Hello Dear;

Could u help me out on the following problem?

I have a string like:

Roll: -3.345 Pitch:54.90 Yaw:-120.01

 

I want to receive just numbers from this string. The length of numbers are different; sometimes positive and sometimes negetive either float or integer numbers.

 

What I got from my code is very clumsy, could you correct me?

I attached the necessary part of code, that is worked for this string:

Result: -3.345,54.90,-120.01

If you have any suggestion, what will work instead of [*,], please let me know.

 

Thanks;

0 Kudos
Message 1 of 9
(2,691 Views)

Try this.

Scan from string.JPG

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
0 Kudos
Message 2 of 9
(2,675 Views)

Hi

Try using scan from string with the below format string

 

%[a-z,:,A-Z]%f%[a-z,:,A-Z, ]%f%[a-z,:,A-Z, ]%f

 

also see the attched image..

0 Kudos
Message 3 of 9
(2,662 Views)

Gak solution is very good if you need the values in numeric format but you will need to convert them if you want the values in string format. You can use the following regex to get the values directly in string format.

 

regex.png

 

Ben

 

0 Kudos
Message 4 of 9
(2,617 Views)

Thanks all for reply.

It doesn't work. Let me send you my complete program.

The data continuosly comes from the serial port. After I filter the numbers, I will send them ona file.

 

I attached my previos work which works now. And the new veersion which I am looking for, this version is based on helpof you guys.(Thanks).

 

 

Best;

 

Download All
0 Kudos
Message 5 of 9
(2,570 Views)

Ben,

I tried your regexp too, the output was empty.

0 Kudos
Message 6 of 9
(2,563 Views)

@skh wrote:

I have a string like:

Roll: -3.345 Pitch:54.90 Yaw:-120.01

 


Is this the exact string that you receive or just something close? There is a blank space between Roll: and the following number but not for pitch and yaw. Can you post the content of the read buffer output of the VISA Read function? (connect a string indicator to this outpu)

 

You can also try the following regex:  \s*Roll:\s*([-\d\.]+)\s*Pitch:\s*([-\d\.]+)\s*Yaw:\s*([-\d\.]+)

 

Ben

0 Kudos
Message 7 of 9
(2,545 Views)

Thanks Ben;

The second expression worked great:).

s* before the Roll, Pitch , Yaw means a string?

 

Cheers;

 

0 Kudos
Message 8 of 9
(2,526 Views)

\s Matches any white space character (space, newline, tab, carriage return) and the star * is a special character that marks part of a pattern that can repeat zero or more times. So \s* will match zero or more white space character.

 

Ben

Message 9 of 9
(2,516 Views)