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.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

regular expressions

Hello, I am using a python script to retrieve test limits from a MS Word document. For each limit the script finds, it sends a string "hwTestLimit:<test_limit>" to standard output. So after my script is done, I get a bunch of these lines. There are also other lines for other types of information mixed in. What i would like to do is possibly use regular expressions to get all the <test_limit> strings from the standard output buffer. To use the built-in string functions, it appears I would need to know the number of characters after a sub-string match which I won't know ahaead of time. All I will know is that the string I need starts after "hwTestLimit:" and end before a new line character. It appears Test Stand 4.2 supports regular expressions but I can't seem to find any examples on how to use them within Test Stand.
0 Kudos
Message 1 of 10
(5,461 Views)

Hi JulesG,

There is a DevZone Tutorial Calling Scripting Languages from NI TestStand.  I also recommend the tutorial Introduction to Scripting in Perl, Python and Tcl.  As for regular expression, the TestStand Help contains the following: NI TestStand™ 4.2 Help - Regular Expressions

0 Kudos
Message 2 of 10
(5,418 Views)
Hi EadieU, yes I've read the help on regular expressions but I'm not sure how and where I can use it. For example, can I use it with the string function Find()? If so, how is it used? Can I place a regex match string in place of the substring parameter?
0 Kudos
Message 3 of 10
(5,403 Views)

Hello JulesG,

 

Unfortunately the use of regular expressions in this case will not be possible. My first recommendation would be to store the standard output string in a String Property then pass that String to a code module (LabVIEW, CVI, .NET, whatever you're comfortable with) to parse it and return an Array of Strings.

 

If you absolutely must use TestStand's Functions, you may be able to accomplish your task by implementing the following pseudo-code:

 

 

Store Standard Output string in a String variable like Locals.myStandardOutput

 

 

Locals.startIndex = 0

Locals.endIndex = 0

 

Locals.arrayIndex = 0


While(Locals.startIndex != -1)

{

Locals.startIndex = Find(Locals.myStandardOutput, "hwTestLimit: ", Locals.endIndex, True, False)
If(Locals.startIndex == -1)
{
Break();
}
Locals.startIndex = Locals.startIndex + 13 //This will make startIndex equal to the index of the first character of the string
                                                            //following "hwTestLimit: "
Locals.endIndex = Find(Locals.myStandardOutput, "\n", Locals.startIndex, True, False)
Locals.mySubString[Locals.arrayIndex] = Mid(Locals.myStandardOutput, Locals.startIndex, Locals.endIndex - Locals.startIndex)
Locals.arrayIndex++
}
 
Note: Locals.mySubString will have to be an Array of Strings with a pre-defined size so be sure to make it large enough to store all of your substrings. Also, note that this is simply pseudo code and I haven't necessarily tried it or tested it so you may need to make a few tweaks.
Manooch H.
National Instruments
0 Kudos
Message 4 of 10
(5,382 Views)
Thanks Manooch_H, your suggestion is what I've already implemented. It would have been nice of I could have implemented regex right in Test Stand though. I could passed the std output back into another python script to parse the lines but the extra code involved didn't make it worthwhile.
0 Kudos
Message 5 of 10
(5,368 Views)

I am trying to do the same thing.  It would be nice (wish list) if Teststand could expose Regular Expression use in the built-in String functions without having to write something in external code modules...

Message 6 of 10
(4,527 Views)

You can post this idea in the Idea Exchange forum, which is monitored by NI's R&D!

 

http://forums.ni.com/t5/NI-TestStand-Idea-Exchange/idb-p/teststandideas

0 Kudos
Message 7 of 10
(4,525 Views)

Though perhaps not as good as built-in, you can use the .NET adapter to call the .NET framework's regular expression libraries without having to write a code module.

 

Hope this helps,

-Doug

0 Kudos
Message 8 of 10
(4,504 Views)

That sounds good.  What .NET assembly would I be looking for?  Or what root class would I call?  Can you provide a simple example?

0 Kudos
Message 9 of 10
(4,486 Views)

I answered my own question.  See the attached picture.

 

NetRegExSetUp.JPG

 

 

Message 10 of 10
(4,477 Views)