Best answer

How to set up a Zapier text filter for multiple possible values within sentences?

  • 10 January 2024
  • 3 replies
  • 191 views

Hi,

I’m trying to filter messages and setting condition that looks on the text and continue if it contains one of possible values.

I’ve tried using “Is In” and in the values specifying multiple values separated by comma, but it doesn’t work if the original text had other words beside of the filter ones.

Examples :

My text : I ate many candies

My text : who likes Banana ?

Filter : My Text Is in (Banana, candies , apples)

 

I would like both of these messages to be filter by this condition , but it would only filter if my text contain the exact word :

For examples the following text will be filtered

My text: candies

 

Thanks

icon

Best answer by SamB 12 January 2024, 10:45

View original

3 replies

Userlevel 7
Badge +14

Hi @lirana 

Help article for using Filter: https://zapier.com/apps/filter/help

Try using 2 conditions

Filed contains X

OR

FIELD contains Y

right. I have 10 values, so I was trying to see if there is more efficient way to do it.

Userlevel 7
Badge +11

Hi and welcome to the Community @lirana! 👋

Perhaps you could use a code step for this? I did some playing around with our AI-powered code generator feature and was able to get a Code step to check for a match for the words in your example and return a value of either true or false: 
d14d0fd17c3d715261294e40761a5d87.png
dd2b19b7d6f627b4dd78cebe0d3cab4e.png

Here’s the Python code I used for this:

# Define a function to check if a specific word is present in the text
def check_word(word):
# Convert the text to lowercase and split it into words
words = input_data["text"].lower().split()
# Return True if the word is in the list of words, otherwise return False
return word in words

# Define a function to check if any of the given words are present in the text
def check_words():
# Define a list of words to check
words_to_check = ["banana", "candies", "apples"]
# Iterate over the list of words to check
for word in words_to_check:
# If the current word is present in the text, return True
if check_word(word):
return True
# If none of the words are present in the text, return False
return False

# Call the function to check if any of the words are present in the text
result = check_words()

# Print the result
print(result)

# Define the output variable as a dictionary with the result
output = {"result": result}

Then the filter could be used to check the output from the Code action to see if it was true - meaning it found a match.

Hope that helps. If you run into any issues on that do let us know - happy to help further! 🙂

Reply