LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in Match Pattern Function

While using the match pattern function, I found a case where the function fails when it should work. I am using the match pattern function to verify that an ethernet packet is coming from the desired MAC address where the string and regular expression are both strings in Hex display. What I find is when the regular expression is set to 0003E0100024, and a matching string comes in, the result is -1, it can't find the string. If I change the 24 to a 23 or 1D, it finds it. I'm attaching a sample vi where I have a work-around of just using the = function, but don't understand why the match pattern function is not working. This is the first time I've seen it fail, but worry that it is not reliable if I ever use it again.
0 Kudos
Message 1 of 5
(3,944 Views)
It's not a bug but the way the function uses regular expressions for determining a match. Turn on '\' Codes Display for String 2 and you'll see several '\' characters. The '\' symbol is a special character that (from the LabVIEW help) "Cancels the interpretation of any special character in this list". Use your workaround or translate the hex you receive into ASCII strings.
0 Kudos
Message 2 of 5
(3,944 Views)
You have to be VERY careful when using the Match Pattern function. It uses Regular Expressions which have a syntax and "special characters" associated with them. The issue that you are facing is that the string you are trying to match, has a "special character in it" 0x24 is the "$" character which is used in regular expressions to anchor the pattern to the end of the string. In order to ignore this special meaning, you need to escape it with the "\" (0x5C) character.

Wrong ==> hex"0003 E010 0024"
Right ==> hex"0003 E010 005C 24"

Other characters that need to be escaped are:

".", "?", "\", "^", "[", "]", "+", "*", "$", "-", "~".

I have attached a revised version that uses a special tool to escape special characters for Match Pattern.

Goo
d luck,

-Jim

PS - make sure to read up on the LabVIEW online help for Match Pattern. It has lots of examples on how to use Regular Expressions.
0 Kudos
Message 3 of 5
(3,944 Views)
Denis,

I am sure that you know this, but slash codes would display a "\" char as "\\". You can see that there aren't any slashes in the string being used in the RE, but rather the slashes are shown to display the non-displayable chars like the Null Char (0x00) ==> "\00". It is really the "$" character at the end of the string causing the problems, which needs to be escaped as "\$".

-Jim
0 Kudos
Message 4 of 5
(3,944 Views)
You're correct. Jumped to conclusions when I turned on the slash codes display.
0 Kudos
Message 5 of 5
(3,944 Views)