LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Find all numbers after zero or one ":" character using Match Pattern

Solved!
Go to solution

Hello

 

I'm trying to convert all numbers inside a .txt file to DBL.

My filename have the following text (an example):

Text file.png

Note that some lines have the ":" character, while others don't have (because they came from different sources)

 

My subVI is reading the .txt file and trying to convert all numbers after the ":" character OR (if the ":" is not present) convert all number in that line.

But my first match Pattern isn't working.

Can someone help me correcting this error?

 

Here's the snippet of my subVI:

snippet.png

Here's the result:

 

Result.png

 

Download All
0 Kudos
Message 1 of 6
(2,766 Views)
Solution
Accepted by mthheitor

Hello,

for the first match you should change [:]? to [:]+   , you are looking at least for one colon.

If no colon is found you need the "before substring" in the second match pattern.

Example_VI_BD.png

 

Message 2 of 6
(2,735 Views)

Here's a pretty disgusting looking regex that should do the job.

(?(?=.+?[:])(?>[:])[-]?[.]?[0-9]+[.]?[0-9]*|[-]?[.]?[0-9]+[.]?[0-9]*)

 

It looks ahead for the [:], if its there it matches as part of a non capturing group followed by your normal numeric group, otherwise it matches the normal numeric group.

 

0xDEAD

 

Message 3 of 6
(2,722 Views)

@deceased wrote:

Here's a pretty disgusting looking regex that should do the job.

(?(?=.+?[:])(?>[:])[-]?[.]?[0-9]+[.]?[0-9]*|[-]?[.]?[0-9]+[.]?[0-9]*)


You can probably (haven't tested) clean up a bit by replacing [0-9] with \d:

(?(?=.+?[:])(?>[:])[-]?[.]?\d+[.]?\d*|[-]?[.]?\d+[.]?\d*)

 

@OP: could you post the desired output? As I read it now, a line without a ":" should output all it's numbers?

Message 4 of 6
(2,716 Views)

@Ulib Thank you. It worked

@deceased Thank you. But I stick with Ulib code, because it was more simple 🙂

@wiebe@CARYA Yes, it does have a bug with a line without a ":" and numbers before the measurements. But for the data we have now, it's gonna work.

 

0 Kudos
Message 5 of 6
(2,644 Views)

@mthheitor wrote:

@wiebe@CARYA Yes, it does have a bug with a line without a ":" and numbers before the measurements. But for the data we have now, it's gonna work.


Unspecified, but easy to change. 

never mind mixing up threads

0 Kudos
Message 6 of 6
(2,636 Views)