Determine if a word is in a text string

This should be simple. If a word is in a given text string the outpout should be true, else false. Can you please show me the code for this. I have searched on google, on reddit and on here. Even tried ChatGpt. I would like to use this to change the calendar day colour when a key word appears in my calendar notification. Thanks.

$if( gv(day)!= "SUNDAY", false, true)$


$if( gv(day)= "SUNDAY", 1, 0)$

Actually I want to test for finding a word in a given sentence. Something like if(function(“hello world”, “hello”,),“true”,“false”). Then once I know it is working replace “hello world” with a notification using the ni function.

I already tried different functions with the help of ChatGPT. But none of them worked.

I can use tc(reg… to replace a word if it is found in a sentence. So I suppose I could then compare the sentence with the original one, and if different the word was there. But that seems so convoluted.

If anyone needs this I am posting a solution. BUT it is convoluted - there must be a more direct code.

In this example if “sample” is in the original sentence it will be replaced with “pickle”.

$if(tc(reg, “This is a sample sentence.”, “sample”, “pickle”)=“This is a sample sentence.”,0,1)$

Here the equality is false because the word was found and replaced, but it outputs 1 to imply sample is in the sentence.

$if(tc(reg, “This is an example sentence.”, “sample”, “pickle”)=“This is an example sentence.”,0,1)$

Here the equality is true because the sentence is unchanged, and outputs 0 implying “sample” is not in the original sentence.

1 Like

You need to use the regexp operator, for example

$"this is a test" ~= is$

Will return 1 since sentence contains “is”

1 Like

Thank you! Wow so simple.

to be precise i think it’s \bis\b.
using only is will also match this or miss. adding \b will only match is

1 Like

Thank you for that. Omitting the first letter of the word puts the inclusiveness to good use if the first letter might be upper case, and the word is long. E.g. holiday → oliday.

a simpler way will be using tc(low) on the test text instead. omitting the first word might match undesirable word like boliday or coliday (not actual word, just theoretically. :sweat_smile:)

Yes. My approach was a hack, this is much more sensible. Thanks.

This topic was automatically closed 25 days after the last reply. New replies are no longer allowed.