LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

bracket in Regular Expression constant?

Solved!
Go to solution

I am a bit puzzled by the behavior I am experiencing in LV 2011. I hope to get some light from experts out there.

I am trying to parse a messy ASCII header file and after having split it into individual lines (strings), I use the "Match Regular Expression" function to remove some of the info before the substantial information.

Some of the strings include square brackets ([, ]), which are special characters for the function, therefore, as documented in the help, one needs to precede them with a backslash.

 

Example:

 

I want to parse the following line:

 

   #PR [PR_DEV,I,2]

 

One way (which I am using because of considerations related to the rest of the header) is the the following:

 

ScreenHunter_002.jpg

 

Note that the first string constant is using "Code Display" whereas the second one is using "Normal Display".

Why did I not put a backslash in front of the bracket in the first string, you may ask? Well, I did, but it disappeared after I typed the other characters. And reverting to "Normal Display" did not restore it.

Of course, the first version does not parse the input string correctly, whereas the second one does it fine.

In other words, the custom display string (which is convenient for cryptic codes such as \s* or to distinguish between space and tab...or simply ENTER tabs!) seems to mess up with the \[ combo (likewise with the \] one).

It is not a huge deal. I can use the "Normal Display" mode, but I tend to think that this qualifies as a hidden "feature". And again, it is still a pain in the ... when dealing with special characters such as tabs, etc...

0 Kudos
Message 1 of 3
(3,656 Views)
Solution
Accepted by X.

I think that [ is a special character which needs to be preceded by a backslash, but it is not one of the defined backslash characters (like \s). So, you need to put in two \\ to get one \ while in '\' Codes Display.

 

You can put in any character by using \xx where the xx is a hex character using only upper case letters for A..F.  I converted the strings to byte arrays and tried to see what made the arrays match and the Match work.

 

Lynn

 

 

RegEx.png

 

 

Message 2 of 3
(3,647 Views)

Of course! I should have known better... Still, the fact that when typing \[ in "Code Display" mode, one ends up with just [ is sort of misleading.

I actually just verified that if you type \[ in normal mode and switch to "Code Display", it turns into \\[.

0 Kudos
Message 3 of 3
(3,626 Views)