LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Match Pattern Bug?

If you pass Match Pattern an empty string, and a pattern of ".*", ie zero or more of any character, it doesn't match - the offset past match is -1. This is not what I expected, for example perl will match an empty string to ".*" - Is this a known bug?

Ian
0 Kudos
Message 1 of 4
(3,218 Views)
Interesting question. The help indicates that ".*" should match any string including "zero instances". Help on this function says:
The offset input and the offset past match output might be equal when the empty string is a valid match for the regular expression.
but I can't get it to match an empty string either. I guess I'd say it's a bug.

You'll probably have to do a dual check, first check to see if it's an empty string (use equal to instead of Match Pattern), then if False, use your Match Pattern -- Hmmmm, does that do it for you? If it is NOT an empty string, then it is a string. What's the purpose of matching on ".*" anyway?

Sorry I wasn't more helpful.

Tim
0 Kudos
Message 2 of 4
(3,218 Views)
Thanks Tim, at least you have confirmed thats how it works. As for the purpose of matching on .*, I am examining a serial data stream from an old system looking for one of several patterns to process ... I was going to use .* as a default pattern 'at the end' as it were to catch everything not already matched. This was just to allow me to write it in a uniform & hopefully elegant fashion. Now I'm just grabbing anything left at the end without a pattern match.

Ian
0 Kudos
Message 3 of 4
(3,218 Views)
Further to my original post, I have also found that Match Pattern doesn't take kindly to control characters as 'any character':

Trying to match [^b]* for example, with a string aa\02aa (ie its got a binary 2 in it), results in a match of aa & remainder of \02aa. This applies for any character between \00 and \1F. Any other character, eg aaXaa results in a match of aaXaa & no remainder.

On the other hand, .* matches strings containing characters with values < \20 quite happily.

😞

ian
0 Kudos
Message 4 of 4
(3,218 Views)