LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question regarding regular expressions that should match brackets

Hello!
 
I was trying to create a regular expression for the "Match Pattern" VI that matches patterns like "NumericArray2D[0..9][0..1]". In order to match the "[" I added the expression "[[]" as showed in the online help. It worked fine so far but when I added the expression "[]]" to match the "]" it didn't work any more. Even the second expression alone never matched a "]", although the first expression matched the "[". So I figured I should add a "\" and the pattern "[\]]" (even without the brackets, "\]") finally worked.
My working pattern looks like this: "NumericArray2D\[[0-9]+..[0-9]+\]\[[0-9]+..[0-9]+\]".
So I'm wondering why "[]]" doesn't work. Is it a bug? When it's not a bug, why do you suggest the pattern "[[]" instead of "\[" for the opening bracket in the online help?
 
Maybe it's already fixed in a later version, I am still using Labview 7.0 right now.
 
 
Stephan
 
0 Kudos
Message 1 of 10
(3,831 Views)
I don't know the specific answer to your question, but I always use the backslash as a signifier to treat the next character literally.  The backslash is commonly used in UNIX and C for this purpose.  The help screen should not list [[ as a way to treat the open bracket literally.  It should always list the backslash, \[.
- tbob

Inventor of the WORM Global
Message 2 of 10
(3,822 Views)
I also usually use the \ to get the actual character code of that symbol. I just didn't do that this time because of the suggestion in the online help. It didn't take long to figure out what the problem was but I just thought I should let you people know and NI should change that in their help (if they didn't do it yet).
0 Kudos
Message 3 of 10
(3,820 Views)
It's not a bug, and neither is the documentation incorrect. When you use "[[]" (open-open-close) it works because the "[" and "]" indicate a list of alternates, and this case you have just one character, "[". When you use "[]]" (open-close-close)  your list of alternates is a null string, and the remaining "]" doesn't mean anything to the Match Pattern function, so it doesn't find what you're asking for (which is null). Its behavior is consistent and correct.

As the previous posters indicated, to do what you want you need to use the escape character.
0 Kudos
Message 4 of 10
(3,799 Views)
Just a little note.  Most of the people who reply on this discussion forum are just users of LabVIEW who take time out of their own day to share their knowledge of LabVIEW, so the people who are replying did not "suggest the pattern "[[]" instead of "\[" for the opening bracket in the online help."  Please keep this in mind when asking questions. 
0 Kudos
Message 5 of 10
(3,800 Views)

@John Rich wrote:
Just a little note.  Most of the people who reply on this discussion forum are just users of LabVIEW who take time out of their own day to share their knowledge of LabVIEW, so the people who are replying did not "suggest the pattern "[[]" instead of "\[" for the opening bracket in the online help."  Please keep this in mind when asking questions. 


I think you missunderstood me John. When I was talking about the "online help" I was actually talking about the Labview help system (The F1 one thing 😉 ). That's where they suggest the pattern "[[]" for parsing an opening bracket.
 
 smercurio_fc:
Your explanation makes sense. That could be the reason. But again, they should have chosen the "\[" expression in the help.
0 Kudos
Message 6 of 10
(3,786 Views)
Yes, I understood that you were talking about the online help.  Because of the way you worded your question I just wanted to make sure that you didn't think that the people that you were talking to here were NI people.  There are often people who come into these forums thinking that they're dealing with NI tech support staff. 
0 Kudos
Message 7 of 10
(3,782 Views)
I know that most people around here are non-NI people. But I also know that many NI folks are active here. I just reread my question and got your point. My question was directed to NI and not to the people around here. Next time I'll try to make it more clear.
0 Kudos
Message 8 of 10
(3,777 Views)
That's OK.  By the way, I do see your point on the documentation.  Just because one way works does not mean that it should be the recommended approach, especially when it could lead to confusion for cases in which that approach doesn't work.
0 Kudos
Message 9 of 10
(3,769 Views)
Not to split hairs, but it's not "could be the reason". It is the reason because that's how the function works. As for the documentation, that's debatable. The example given is correct for what it's showing, though there could have been a note indicating that the corollary search of "[]]" would not work because of the reasons I stated. As I said, debatable because the information I gave is in the documentation - that's where I got it. Besides, just because trying to use "[]]" to search for "]" doesn't work because of how the function operates doesn't make the example wrong.
0 Kudos
Message 10 of 10
(3,767 Views)