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 with bracket [] (again, but different)

Hello,

I have got the following issue. I have a file A.txt that contains few Mb of texts of this format (5 to 10.000 lines):

abcd parameter [1]

efgh parameter [19]

ijklmop variable [5]

...

 

A portion of my program reads chains of caracters from another file. These terms are for instance parameter [19]. I would like to know if this term belongs to the large A.txt file. I am aware that I need to add the backslash \ in front of the bracket if I want to use the match pattern function unfortunately in my case the argument (pattern to match) varies accroding to what the program will read (in a loop). Am I forced to replace the bracket by a \bracket with the find and replace function before using the match pattern function? This is very time consuming.


Thanks for any sugegstion,

Christophe

0 Kudos
Message 1 of 7
(3,308 Views)

Christ0phe wrote:

 Am I forced to replace the bracket by a \bracket with the find and replace function before using the match pattern function?


Yes. This is by design.

 


This is very time consuming.


What is time consuming? The execution of the Search and Replace String function, or, are you doing something else? Perhaps if you post your code it might make it a bit more clear. 

 

0 Kudos
Message 2 of 7
(3,298 Views)
The 'search and replace' takes time if I have to apply it in sequence to the elements that are read (by line) simply because there are 10.000 lines. So whether I feed the search and replace with the whole file or individually times 10.000 it is a huge time. Maybe I should use something else than match pattern but I do not know which one.
0 Kudos
Message 3 of 7
(3,291 Views)

I guess I'm not understanding what you're doing. You said you want to look for "parameter[19]" (as an example) in your A.txt file. Why are you replacing the text that you read from A.txt? You shouldn't replace anything in there. You replace the "[" in the string that you're looking up ("parameter[19]").

 

If I did not understand correctly then please post your code, as well as an example text file (compressed, please). 

0 Kudos
Message 4 of 7
(3,279 Views)

Hello again, thank you for your patience and sorry not to have been clearer. I think you will find a better explanation in the attached vi that is only an extract from the main vi that I wrote. It works, sure, but its heavy and time consuming. I was wondering it there was a nicer way to code the same function.

Thanks again,
Christophe

0 Kudos
Message 5 of 7
(3,257 Views)

Christophe,

 

The example you posted has a different format from the data in your original post. Is the numeric part inside the square brackets [ ] or before the brackets?  In your example VI you could simply search for "Parameter xx" and then adjust the offset past the match to account for the "[s]" part.

 

Your VI has two lines with "Parameter 7".  Does your real file have multiple lines with the same parameter value?  Do you need to find all the multiples?

 

I would consider parsing the numeric part from the strings in file B and concatenating those with preformatted search strings (with the \[ combinations).  I think this might be a bit faster than doing multiple search and replace operations.

 

Lynn

0 Kudos
Message 6 of 7
(3,251 Views)

The strings given in the example are just ... example. There can be anything inside the [ ] and also anything before or after it. There could be many other possibilities than "Parameter". Actually, "Parameter" is the name of a physical parameter: temperature, pressure, flow,... and the units between [ ]. The same parameter name might appear more than once and the different occurences must be traced. I cannot parsing the way you propose as there is not necessary a numeric part.

If there is no possibilities, I would maybe match \[ and forget the unit part, taken into acount only the parameter name.

Thanks,
Christophe 

0 Kudos
Message 7 of 7
(3,239 Views)