ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

regular expression help

Solved!
Go to solution

Hello,

 

I have a string I want to employ a regular expression on to avoid a cascade of match patterns, but I can't seem to get it to work.

 

The string:

 

^XA~TA000~JSN^LT0^MMT^MNW^MTT^PON^PMN^LH20,0^JMA^PR4,4^MD0^JUS^LRN^CI0^XZ
^XA^LL0076
^PW376
^BY25,25^FT25,38^BXN,2,200,0,0,1
^FH\^FDP1000^FS
^FT0,56^A0N,20,20^FH\^FDP1000^FS
^FT180,65^A0N,42,40^FH\^FD^FS
^BY25,25^FT150,38^BXN,2,200,0,0,1
^FH\^FDP1001^FS
^FT120,56^A0N,20,20^FH\^FDP1001^FS
^FT180,65^A0N,42,40^FH\^FD^FS
^PQ1,0,1,Y^XZ

 

What I want out of it is one instance of:

 

P1000

P1001

 

In this example. The number portion will be different for other strings, such as P4567, PA34554, etc. It will never vary from P or PA. The number section might be 4 or 5 digits long.

 

Each of these show up twice in the string.

 

The regex I was trying to use is:

 

\^FD*\^FS

 

and then I was going to weed out the duplicates.

 

And now my brain gives up.Smiley Sad

 

Tay

0 Kudos
Message 1 of 8
(4,909 Views)

The characters "\" and "^" have special meanings in regular expressions.  Why don't you just search for P and PA, followed by numerical characters?

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 8
(4,897 Views)
Solution
Accepted by topic author slipstick

This vi extracts all P followed by numerical characters.  You have to modify it to include PA.

 

17993iE5847D04BBA462D2

- tbob

Inventor of the WORM Global
Message 3 of 8
(4,894 Views)

Thanks. I wasn't able to get the P or PA search to work either. I don't use regex functions enough to be really familiar with them.

 

Tay

0 Kudos
Message 4 of 8
(4,889 Views)

Or this...

 

18031i00A8E35BC5E510CD

 

 

I learned a lot from this site.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 5 of 8
(4,862 Views)

@jcarmody wrote:

 

I learned a lot from this site.


 

I need to learn regular expression.  That site has a lot of info.  Thanks Jim.

 

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 8
(4,839 Views)

Excellent site! And thanks for the code!

 

Tay

0 Kudos
Message 7 of 8
(4,832 Views)

I was on travel so I couldn't reply earlier, but I was glad to see Jim defend the honor of the regex.  Call me old-fashioned, but I do not have OpenG installed on all of the machines I come across.  Instead of deleting the duplicates, what I do instead is to use the attribute of a dummy variant to hold the values.  Duplicates are nicely handled and the final iteration errors out when you try to write an empty name.  I do not use it here, but I made the number itself a capture group, so the value of each attribute is the number itself.

 

18075iCAB38B4EC0C68457

Message 8 of 8
(4,805 Views)