Showing results for 
Search instead for 
Did you mean: 

Issue in Match Pattern in string operation, offset past match does not return the index as expected

Go to solution

Hello Application engineers,


I used Visa Read to read data from a USB serial port, then used a Match Pattern to find an index (offset past match) in the read buffer string as shown below,



The front panel is as below in hex display.. 




Issue: The returned offset past match is not as what I thought  to be 6 when regular expression is  4C120100042A; and to be 7 when regular expression is  4C120100042A01. They are 5 and -1 respectively.


regular expression            offset past match

        4C                                             1

        4C12                                         2

        4C1201                                     3

        4C120100                                 4

        4C12010004                             5

        4C120100042A                         5

        4C120100042A01                   -1

        4C120100042A0107               -1



Could someone explains why?


Code is attached.



0 Kudos
Message 1 of 5
Accepted by topic author edmonton

Don't use Match Pattern with binary data. Match Pattern can use special characters to search for regular expressions in string. In your case, at some point, you are searching for 0x2A which is "*" (special character) so result is not what you expect. You can search in the function detailed help to see what each special character does.

To check if a string is a part of another string use Search/Split String instead! Be careful that this function returns the offset of match instead of offset past match.

Message 2 of 5

I think it has to do with non-printable characters.  I know for sure that null character is not allowed, and you have a null character in your regular expression.  I guess my question is why do you need to do this?  Maybe we can think of a better way to do whatever it is you are trying to do.

(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.
Message 3 of 5
Accepted by topic author edmonton

To complete what LucianM said:


Search Hexadecimal Substring.png


Message 4 of 5

Thank you LucianM,


In the read buffer string, there are device register address, data register address and data value, I need to obtain the data from a specified device and data register addresses (or regular expression), so I can extract data starting from the offset past match, The Search/Split String works fine for me. 



0 Kudos
Message 5 of 5