LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Read Numeric Symbols Only within Specific Sequence of a String using Lexical Class Type

Solved!
Go to solution

Hello, 

 

I had a look at some archive posts regarding reading specific characters in a string. 

 

One that I was really enticed by was Altenbach's example using Lexical Class Type: Re: Removing non-alpha-numeric characters from a string

 

Reading_Integers_Only.PNG

 

I have attached the VI so you can have a look. 

 

The only drawback at the moment is that I only want to identify the first sequence of numbers and then stop. For example, I have a string which reads: An-54

 

Currently the VI indicator will be 54 because the for loop goes through the entire string. I actually only want 5 to be read because a special character follows. I am not interested in any numeric (code 3) afterwards. 

 

Here are a few more examples to clarify what I want to achieve: 

 

Input: AC1505  

Desired Output: 150 

 

Input: AI>00005

Desired Output: 0000 

 

The desired outcome is for the match to occur with only the first sequence of number/s (from left to right) and stop matching once a different code (other than 3) is read. 

 

Would anyone have any ideas on how to achieve that? 

 

Many Thanks

0 Kudos
Message 1 of 5
(2,642 Views)
Solution
Accepted by topic author neunited

Is there any particular reason for using the Lexical Class node here? It's a pretty straightforward regex. If you really want to do it with lexical class, you can make your loop conditional and use a boolean shift register to keep track of whether matching has started.

Message 2 of 5
(2,623 Views)

Lexical Class is a better option performance wise in comparison to the "search and replace all" which is a multipurpose VI. For parsing and matching the lexical class seemed to be a more viable option to use. 


However the issue now is that I actually want to include all minus signs and decimal places, for example:

 

Input: BK-0.03:

Desired Output : -0.03

 

One possibility could be by adding further conditions in the case structure or with the use of enums. 

 

Let me know if you have any better suggestions. 

 

Many Thanks

0 Kudos
Message 3 of 5
(2,562 Views)

I managed to solve my own query. 

 

VI attached for your reference. If you have any other alternatives feel free to share them Smiley Happy

0 Kudos
Message 4 of 5
(2,555 Views)

I have my doubts that your lexical processing is more efficient than the regex and the regex is certainly more compact.

In almost all cases, I would expect the performance difference to be negligible. If it is important to you, I'd be curious to see how the benchmarks show out.

 

I think your approach could be further simplified to use a conditional tunnel on the output. You've also created an artificial stop condition in this case where you had to know that your last digit/term character was 3.

Lexical Digit Grab.png

Your approach is the top one. My regex is the bottom.

0 Kudos
Message 5 of 5
(2,541 Views)