LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

lazy (not greedy) match pattern

Hello
 
I want to use match pattern to return every substring enclosed between 7E characters in a hexadecimal string.
 
The string looks like this : ....7E7E ....7E7E....7E7E...
 
I used the following regular expressions: 7E.*7E, 7E .+ 7E, 7E .+?7E but they return nothing or they return the maximum match possible (greedy match). (The regular expressions actually not like this because 7E is in hexadecimal representation and the other characters are not, the expressions would look like this: ~.*~, ~.+~, ~.+?~)
 
Is there a way to perform non-greedy matches in LabView?
 
Thank you for your help
 
 
0 Kudos
Message 1 of 9
(5,158 Views)
Hi forsaken,

what about this little sub-vi:

'data string' is your data value (without surrounding 0x7E), 'remaining string' is therest of the string (with 0x7E).

Message Edited by GerdW on 06-05-2007 04:44 PM

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(5,146 Views)
You could also use "Spreadsheet String to Array".

Daniel

Message 3 of 9
(5,128 Views)

I guess I did not explain myself correctely.

Each string starts and ends with 7E. That's why my regular expression was 7E.+7E.

My first solution was to implement a shift register with match pattern to return every matching string in an array but all I gos was the longest matching string.

Here is my primary (not working correctely) solution:

Can anybody help?

Message Edited by Forsaken Angel on 06-05-2007 10:45 AM

0 Kudos
Message 4 of 9
(5,119 Views)

I forgot to state that I also would like to keep the 7E delimiters at the start and end of each substring in the array.

Thanks

0 Kudos
Message 5 of 9
(5,104 Views)
Your best solution I think would be Daniel's suggestion, but a couple comments are in order. First make sure the display mode for the string constant holding the delimiter is set to hex display or '\' codes. Otherwise you will be looking to match the ASCII characters "7E" not the hex value 7E or \7E.

Second, I would modify the delimiter to be 7E7E because this character occurs at both ends of the message so you will see two consecutive 7E characters between the messages. If you do a single 7E character my suspicion is that you'll get an output array where every other element is empty.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 6 of 9
(5,101 Views)

Thanks

Daniel's solution did it. The problem is that I still need the 7E characters on the strings where there was a match.

I could concatenate the character at the beggining and end of each substring but that would not be correct, because I could just receive part of the string (this program will be integrated with serial communication), and it would place a 7E character in the middle of a string that has not been fully received.

0 Kudos
Message 7 of 9
(5,087 Views)
Yes, before going into Daniel's code you will need to strip off everything that occurs before the first 7E character including the delimiter character's themselves, and everything after the last 7E character, again including the delimiter characters.

One complicating factor is that there could be 1 or two delimiters at each end depending upon exactly when the receive started and stopped relative to the serial data stream - on the other hand  you only have to figure it out once because you can take the raw string, run it through the stripper, reverse it, run it through the same stripper again, reverse it one more time and go into Daniel's code... The resulting array should only contain complete messages.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 8 of 9
(5,074 Views)
Good points, Mike.

To keep the delimiters (7E) at the strings, I don't see a solution by just using match pattern. What you could do is match pattern to match the delimiter (7E7E) and a split string. See attached image.

Daniel

Message Edited by dan_u on 06-06-2007 10:06 AM

Message 9 of 9
(5,040 Views)