07-01-2010 03:27 PM
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.
Tay
Solved! Go to Solution.
07-01-2010 03:58 PM
The characters "\" and "^" have special meanings in regular expressions. Why don't you just search for P and PA, followed by numerical characters?
07-01-2010 04:11 PM
This vi extracts all P followed by numerical characters. You have to modify it to include PA.
07-01-2010 04:31 PM
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
07-02-2010 05:38 AM - edited 07-02-2010 05:39 AM
07-02-2010 12:59 PM
07-02-2010 01:10 PM
Excellent site! And thanks for the code!
Tay
07-03-2010 11:55 AM
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.