LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

match pattern anomaly?

Hi All,

I must be missing something very obvious here! Can anyone tell me why this VI does not work?

Its a very simple match pattern example which is actually taken from the match pattern VI icon itself:

string: abbc
reg exp: b*   (which to my understanding will match "b" and any number of "b" following immediately after
offset 0

output should be (I think)

before string: a
match pattern: bb
after: c

However I actually get:
before string: <nothing>
match pattern: <nothing>
after: abbc
offset: 0

Where am I going wrong??





0 Kudos
Message 1 of 19
(3,835 Views)
I think what you're looking for is a regular expression of:

[b]+

This will match 1 or more consecutive 'b' characters.
intvsteve
LabVIEW R&D
0 Kudos
Message 2 of 19
(3,831 Views)
Thanks for your suggestion, it works as you said.

I am still a little uncertain about the behaviour though, as according to the help (LV 7.1 electronic help):

* Matches the longest number of instances of the expression preceding * in regular expression, including zero instances. For example, be*t matches bt, bet, and beet.

But if I use their example
string: beeter
reg exp: b*t

I get:
before: bee
match: t
after: er

This does not seem correct as the wildcard should apply to the b and not the t??



0 Kudos
Message 3 of 19
(3,809 Views)
There is something you have overlooked : b*t will match the longest number of instances of b immediately followed by t

Therefore, the function will match : t, bt, bbt, bbbt and so on

So the only match in beeter is t (--> 0 instance of b).
Message 4 of 19
(3,799 Views)
thanks for clarifying this, but I am still confused, going back to the original example:

string: abbc
reg ex: b*

surely this should find bb as a match?
Message 5 of 19
(3,790 Views)
Good point ! The function should indeed match bb ! I'm also confused now !
b+ works as expected but there seems to be a bug with b*.
Or are we missing something ?

The behavior is the same with LV8.2.1.

0 Kudos
Message 6 of 19
(3,780 Views)
Still the behaviour of the function is correct. b* matches 0 or more instances of b. The string starts with 0 instances of b (well, it's a strange way of looking at it but it's true), so position 0 is a match. Before match and match are empty as the whole string is after the match.

Daniel

0 Kudos
Message 7 of 19
(3,772 Views)
So if you search for b*c, you should get "bbc" as a return value.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 8 of 19
(3,762 Views)
well, it's a strange way of looking at it but it's true

The least would be to change the icon of the match pattenr function because the example it shows produces a different result...
Message 9 of 19
(3,754 Views)
I have to disagree, the string abbc contains at least one b, the match pattern is supposed to search within a string so why can't it find the first occurance of the b?

My whole problem stems from the actual LV icon for "Match Pattern"

If you look at the icon, it seems to suggest that if you use "abbc" wired to the input, and b* to the reg exp, then the outputs should be a, bb, and c!

Yet it does not do this...

<edit<> I agree with JB above

Message Edited by nrp on 05-23-2007 03:41 PM

0 Kudos
Message 10 of 19
(3,755 Views)