LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Determine if a string contains a certain expression

Solved!
Go to solution

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!

Message 1 of 7
(25,003 Views)
Solution
Accepted by topic author Djaunl
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.
Message 2 of 7
(25,002 Views)

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! 

0 Kudos
Message 3 of 7
(24,999 Views)

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.

Message 4 of 7
(10,292 Views)

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.

0 Kudos
Message 5 of 7
(6,814 Views)

It's not mandatory to use the search function string outputs. Simply ignore them, the original wire value (input) will not changed.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 6 of 7
(6,799 Views)

OK...Thank you. Got your point.

0 Kudos
Message 7 of 7
(6,781 Views)