LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching for a string using "Match Pattern" or "Match Regular Expression"

Solved!
Go to solution

Hello,

 

   I would like to use the "Match Pattern" or the "Match Regular Expression" vi simply because of the outputs that these vi's provide. The output I am interested in is the "after substring". I want to be able to specify a "substring" and get whatever is after the substring from the input string. However I am getting all confused and/or hosed up when it comes to "regular expressions". Is there a way to create a "regular expression" that will act as is it is a "substring" to find within the input string?

   The substring is a partial dir path that contains colons, backslashes, etc that are part of a directory path.  So some how the "regular expression" input has to ingnore all of the special characters and simply figure out where the substring is within the input string and give me "all of the stuff" after the substring in the "after string" output.

Regards,


Kaspar
0 Kudos
Message 1 of 7
(6,537 Views)

The back slash (\) used in a file path is also a special character in regular expression so you must precede any back slash that you wish to find with a back slash. Like “C:MyDir\\MyFile”

 

Colons are ok.

 

Post an example of what it is you are looking for and I will create a regular expression for you.

 

Omar

Omar
Message 2 of 7
(6,530 Views)

Hello,

 

 

   Here is a example of a of the string value that I want to send to the input string

 

        \\crnas03\home\my documents\test_folder\dir1\dir2\dir3\dir4\file.txt

 

 

Here is the input string that needs to be tweaked to turn into a "regular expression"

 

 \\crnas03\home\my documents\test_folder\dir1\dir2

 

 

I am aware that I will have to uses the "seach and replace" vi to modify it. I would like to get the following output

 

 \dir3\dir4\file.txt

 

 

 

 

Regards,


Kaspar
0 Kudos
Message 3 of 7
(6,507 Views)
Solution
Accepted by topic author Kaspar

Use Match Regular Expression instead of Match Pattern; it's better.

 

regexp.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 4 of 7
(6,497 Views)

Hello,

 

 

  It works! Thank you!

Regards,


Kaspar
0 Kudos
Message 5 of 7
(6,486 Views)

Hi there, thank you for your answer. I completely forgot about escape characters in strings! Anyway, this works for me using both Match Regular Expression as well as Match Pattern. You said to use the former, as "it's better." Could you elaborate on why you say that Match Regular Expression is better?
Thank you

0 Kudos
Message 6 of 7
(4,114 Views)

From the context help, Match Pattern "gives you fewer options for matching strings".  That's all.

jcarmody_0-1626982058507.png

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 7 of 7
(4,101 Views)