06-20-2009 04:11 PM
Hi all,
I feel like there should be a simple way to do this but I haven't been able to figure it out after browsing through these forums, the LV help, and Google.
I want to simply search through a string, determine if it contains a certain expression, and return true if it does, and false if it doesn't. I understand there exists the regex VIs, such as Match Pattern and Match Regex, but those return substrings; I just want a boolean value returned. I could use the Match Regex VI, analyze the output strings to determine if it found a match, and return a boolean from there, but I feel like there's a better, simpler way that I'm overlooking.
In the "additional string functions" subpalette I see there exists Match First String and Match True/False String, but using Match First String seems like it would complicate what I'm trying to do, and I'm not even sure what Match True/False String does; the detailed help is still confusing.
Thanks for any help!
Solved! Go to Solution.
06-20-2009 04:22 PM
06-20-2009 04:24 PM
Dennis Knutson wrote:
There are simple ways. Read the help associated with the search string functions! Each one returns the offset of the found string. It's -1 if not found. A simple Less Than Zero function can be wired to this to return a Boolean. Another way is to compare the returned substring with the Empty String function.
Geez I completely missed that. That definitely solves my problem. Thanks a lot for the quick response!
05-22-2020 09:10 AM
I'm glad to have found a solution, but it's not a satisfying one. There should unquestionably be a "does this string match this regex" VI with exactly two strings as input and exactly one boolean as output. I get that I can make one for myself using the above advice but it feels very clunky and inefficient.
I find the fact that a group of professional programmers could add regex features to their product but leave such a glaring omission totally baffling. I can't get my head around it. I challenge anyone to come up with a good reason this functionality is missing!
The NI ecosystem as a whole has enough to keep me coming back for now, but as a programming language, LabVIEW is abysmal. If NXG doesn't start supporting RIO soon then this will be the last project where I choose NI.
12-16-2021 06:15 AM
Hi,
Is there a simple way to only search a certain expression in an input string. There is 'search and replace function' and 'search and split' function, but I want neither to replace anything nor to split. I just need to get a boolean output (True or False) as to whether the searched string is present or not. I can use the Offset value (<0) to get the boolean output, but the problem is it is deleting the searched string and I don't want it to.
Thank you.
12-16-2021 08:07 AM
It's not mandatory to use the search function string outputs. Simply ignore them, the original wire value (input) will not changed.
12-16-2021 10:32 AM
OK...Thank you. Got your point.