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: 

Duplicate functionality of match pattern

Hi,

 

I need to duplicate functionality of match pattern function with regular expression and scan from string of attached vi.

 

Basically, I want to split the string when a serial number (SN) along with the "XXX" is found within the string.  The working function is with bold font on front panel.  Thanks,

frn

 

 

 

 

 

Download All
0 Kudos
Message 1 of 13
(2,842 Views)

@frn wrote:

Hi,

 

I need to duplicate functionality of match pattern function with regular expression and scan from string of attached vi.

 

Basically, I want to split the string when a serial number (SN) along with the "XXX" is found within the string.  The working function is with bold font on front panel.  Thanks,

frn

 

 

 

 

 


Im not sure I understand.  It's working, soooo...?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 13
(2,831 Views)

I'm sorry, your question doesn't make sense. Right now your code splits the string on any character that is between X and x. Since the string starts <AX, it splits the string at that X. The "after substring" indicator contains the rest of the string, including the V123.12[ZZ1]. You just can't see it because the string has line wrapping enabled, so that portion gets shoved onto a second line, and the indicator only shows one line.

 

What are you trying to do here?

0 Kudos
Message 3 of 13
(2,825 Views)

I need to display "SN XXX" into a separate indicator, using this string as an example: "<AX SN XXX V123.12[ZZ1]" 

 

And I am looking at three different solutions as to select either option: match pattern, regular expression and scan from string.

 

Thanks,

frn

0 Kudos
Message 4 of 13
(2,816 Views)

Is it the exact string "SN XXX" or are the Xs in place of numbers or something else?

 

Do you understand that your "working" solution doesn't actually work, because it simply hides the following text by wrapping it to a new line?

 

If you're just looking for "SN XXX" then you can use that exact string as the pattern to match. You probably don't want to use [X-x], which matches X, x, or -.

0 Kudos
Message 5 of 13
(2,809 Views)

Hi Nathand,

 

Answer to your question:

Is it the exact string "SN XXX" or are the Xs in place of numbers or something else?

 

The Xs are Xs and I tried your approach ("SN XXX") at it works great!  How would you change the other two functions to get the same result: regular expression and scan from string.

 

Thanks,

frn

 

 

0 Kudos
Message 6 of 13
(2,801 Views)

I tried the same approach in regular expression and works too.  How do I change scan from string to duplicate functionality as the other two?

 

attached VI.

 

0 Kudos
Message 7 of 13
(2,795 Views)

@frn wrote:

I tried the same approach in regular expression and works too.  How do I change scan from string to duplicate functionality as the other two?


This is still wrong. Why are you putting the brackets [] around the string you want to search for in Match Pattern? That searches for any one of the characters inside it, instead of searching for the entire string, so you're still not extracting the desired string. After running your VI, put the cursor in the After Substring indicator and hold down the right arrow. You'll see what I mean. Or, right-click that indicator and uncheck "Enable Wrapping."

 

The parentheses around the string for Match Regular Expression are harmless but also not necessary.

 

Scan from String is not useful for extracting specific characters from a string - why would we need a third function that duplicates the other two? Scan from String is good for getting only the variable parts of a string while ignoring the fixed parts, which is the opposite of what you seem to be trying to do.

0 Kudos
Message 8 of 13
(2,792 Views)

Hi Nathand,

 

You are right again.  After I removed the brackets [] it works correctly. I was trying to see the difference between these 3 functions so as to use the best one for my application.

 

Basically what I want to do is to extract any text within a string that contains "XXX" and XXX are litterally "Xs".

Two samples of these strings are as follows:

<TTT BYTE0x0000 ZZXXX CECUXXX AAXXX LXXX  or  <AX SN XXX V123.12[ZZ1]

 

 

How would I extract this text:

SN XXX (space between SN and XXX)

ZZXXX

AAXXX

CECUXXX 

LXXX  

 

Thanks,

frn

0 Kudos
Message 9 of 13
(2,785 Views)

You need to be more specific about what you want to match. How many characters do you want to match before the XXX? If there is a space, will it only ever be immediately before the XXX, or do you also want to match "S NXXX"? Will there always be a space before the text that you want to match, or could it also be at the beginning of the string (immediately after the '<')? In the first example string, do you need to match all 4 occurrences, or just the first one? Do you need all 4 occurrences returned as one string, or as an array of strings? When there are multiple occurences, will they occur in a row, or can there be other text in the middle?

 

Spend some time reading about regular expressions, either in the LabVIEW help or on the web.

0 Kudos
Message 10 of 13
(2,778 Views)