06-11-2019 11:44 PM
Hello
I'm trying to convert all numbers inside a .txt file to DBL.
My filename have the following text (an example):
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:
Here's the result:
Solved! Go to Solution.
06-12-2019 12:51 AM
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.
06-12-2019 02:27 AM
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
06-12-2019 03:16 AM
@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?
06-21-2019 07:01 AM
@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.
06-21-2019 07:58 AM - edited 06-21-2019 07:59 AM
@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