From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Not getting something re: matching patterns in text strings

I'm trying patterns for the first time and think I'm not getting something.  My goal is to start with a raw string, and extract from it the first three letters or numbers I find, without regard to them being contiguous.  I also want to make the letters uppercase.  Here are some inputs and outputs I'd like to get:
 
input output
A           A
a           A
AA        AA
AA+     AA
A+A      AA
A3         A3
ABCD   ABC
2ABCD  2AB
 
The attached VI has 3 versions of this attempt inside it.
 
The first version uses 3 pattern match VIs that peel characters off one at a time and concatenates them.  It seems to do what I want, but I thought I could do something simpler.  This looks to me like a kind of dumb brute force method.
 
The second version is what I thought I could make work.  Is there a matching expression that would do it?  I tried various combinations of () and + and | and other things but didn't hit it.
 
Also, I think the third version should work.  But I never got anything out of the submatch terminals.  Do I misunderstand what they're for or just not know how to use them?
0 Kudos
Message 1 of 3
(2,300 Views)
The first method works and is easy to understand, and if you use the offset parameters instead of the after submatch ones it'll likely be as fast as any other method (I haven't tested it though).

Submatchs are parts of the regex that are within paranthesis.

The attached VI has your first method but with a for loop and is probably what I would use since increaseing the number of matchs becomes easy. It also has a working version using a regex with submatches.

0 Kudos
Message 2 of 3
(2,289 Views)
Matt's first version has a flaw. For example if the input string is lenght =1 and contains a desired character, it will double in the output because the shift register gets set to -1 for the second iteration.
 
I would suggest to modify it as in the attached picture (red insert!).
 

Message Edited by altenbach on 08-18-2006 06:09 PM

0 Kudos
Message 3 of 3
(2,284 Views)