From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Match Pattern and "["

Hello; I'm trying to use Match Pattern (even tried to use Match Regular Expression) where the regular expression contains a square bracket, i.e. "Measurement[0]', "Measurement[1]" and so forth.  I have tried following the help files, by denoting the brackets with "\[" and even concatenating the string to include its own separate bracket "\[" but not getting any results.  Am I missing something obvious here?

0 Kudos
Message 1 of 9
(1,275 Views)

If the text is always going to be exactly what you stated, you can use scan from string with the format of "Measurement[%d]".

 

(I am assuming you want to get the number in the brackets)

 

There are lots of way to parse strings, without knowing more details it's difficult to recommend something.

scan-from-string.png

 

 

0 Kudos
Message 2 of 9
(1,265 Views)

Kyle97330_0-1677259018060.png

I did this and it's working.  What's different about what you're doing?

 

Can you create a VI that you think should work, but doesn't, and post it?  Make sure it has constants for all the inputs so we can run it ourselves.

0 Kudos
Message 3 of 9
(1,240 Views)

I get this:

 

MatchPattern_SqrBracket.png

 

You must have other issues...

Greets, Dave
0 Kudos
Message 4 of 9
(1,237 Views)

The attached is the sort of thing I've been attempting... It just doesn't seem to be working... Granted, it's probably something inordinately silly that I'm overlooking (usually is)... but the solution itself escapes me.

0 Kudos
Message 5 of 9
(1,234 Views)

Can you include a sample file "C:\Projects\00001732_0100284-03_Subset.txt" or similar?  Without that it's not really possible to see what you're having problems with.

 

Also, this is weird:

Kyle97330_0-1677259860493.png

Just do this:

Kyle97330_1-1677259916330.png

 

0 Kudos
Message 6 of 9
(1,226 Views)

Here is the file I've been working with.  It is not generated by any program I am using.  Also, I noticed you changed the square brackets to rounded brackets.  Nonetheless, I will give that a shot.

0 Kudos
Message 7 of 9
(1,128 Views)

OK; tried that; still not working.

0 Kudos
Message 8 of 9
(1,206 Views)

OK, now that I can see the test data the problem is that you're searching for the wrong string in the wrong thing.  You're looking for "Measurement[xxx]" where "xxx" is the line number of the file, but those never line up.  "Measurement[0]" is on line 2, but you search that line for "Measurement\[2\]" so it doesn't find it.  "Measurement[1]" is on line 10 and you search that line for "Measurement\[10\]" with no match, and so on.

 

Also, just in general it's far better to use "Match pattern" unless whatever you're searching for can't be done without using a full regular expression.  Match Pattern runs much faster and is much more stable.

0 Kudos
Message 9 of 9
(1,188 Views)