07-18-2022 05:39 PM
Hi!
When using regular expression in teststand it fails. I am trying to get Stats : READY from the string using regular expression as (Status)\s:\s(READY). Although in the attachment I just tried to get READY and that too is not passing.
Any suggestions on what is causing this?
Thanks!!
07-21-2022 01:46 PM
Does anyone has any suggestions on why this regular expression is not evaluating and teststand returns Failed status?
07-21-2022 06:04 PM
I think the problem is that it's not clear what you are asking for. Is this in a String Value Test step? Or just an expression in TestStand.
What do you mean by "not passing"? It's not doing what you want or the sequence context status is being set to Failed?
Maybe you could give us some more context? Like specifically what are you expecting back from your code module and what is considered passing vs failing?
Thanks,
07-22-2022 02:53 PM
It is a string value type.
I am trying to use regular expression to validate a part of the string that is returned in Step.Result.String from the code module.
So the String is
IMEI : 00009999222 Status : READY
The regular expression that I have is (Status\s:\sREADY)
I notice when I set the UseCompExpr to False, the Step.Status is Failed (previous image)
If I set UseCompExpr to True, it returns Invalid for Comp field (image attached)
All I am trying to achive is to pick the Status\s:\sREADY from Step.Result.String.
Thanks!!
07-26-2022 03:12 PM
Any suggestion as to what is incorrect in performing the regEx?
Thanks
07-27-2022 10:05 AM - edited 07-27-2022 10:05 AM
I got it to work as follows. It seems the Regular Expression has to match everything in the input string. I know with Match Pattern in LabVIEW you can specify part of the string (as you had done) and it will work.
PH
07-27-2022 12:15 PM
Thank you so much, that works although it is interesting that teststand can't return groups.
03-18-2025 07:17 PM - edited 03-18-2025 07:59 PM
The FindPattern function in TestStand behaves like you'd expect it would:
Locals.InputString = "This is a stupid test string"
,Locals.MatchOffset = FindPattern( Locals.InputString, "stupid", 0, True, Locals.MatchLength )
,Locals.OutputString = Mid( Locals.InputString, Locals.MatchOffset, Locals.MatchLength )
,Locals.FoundMatch = Locals.MatchOffset > -1
After that executes, Locals.OutputString is "stupid", Locals.MatchOffset is 10, and Locals.MatchLength is 6.
I am fairly fluent in PCRE and I write regexes, some very complex, regularly, but I was tearing my hair out trying to figure out why I couldn't get the MatchPattern function working with the most basic test. I was about to conclude that it's a completely broken feature until I ran across this thread.
@Teds is correct about the MatchPattern function. You have to write your regex to match the entire string, not just a portion of it:
Locals.InputString = "This is a stupid test string"
,Locals.FoundMatch = MatchPattern( Locals.InputString, ".*(stupid).*", True, Locals.SubMatches )
,Locals.OutputString = GetNumElements( Locals.SubMatches ) >= 2 ? Locals.SubMatches[ 1 ] : ""
You can't just put in something like "\s(stupid)\s", because it only matches a portion of the string.
To me, this is counterintuitive and bizarre, but maybe the NI software engineer that implemented this function was used to a similar implementation in another language.
@lvrat, TestStand can indeed return submatches. It's just weird about it.
Locals.InputString = "I shoved my laptop onto the floor, yelled at the wall, and slammed the door on the way out"
,Locals.FoundMatch = MatchPattern( Locals.InputString, ".*?(laptop).*?(floor).*?(door).+", True, Locals.SubMatches )
After this executes, Locals.SubMatches = { "I shoved my laptop...", "laptop", "floor", "door" }
For anyone else who reads this later, if you're not too familiar with submatches, with a lot of implementations in various languages it's pretty common for element 0 in the SubMatches array to be the full match, followed by the actual submatches.
The TestStand documentation (at the time of writing this) is not at all clear about this quirk with MatchPattern.
Have fun.
Mr. Jim