Skip to main content
Best answer

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


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

Best answer by SamB

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: 
40978ffc1e7766c0e3f8d07724416cbc.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"]
    # Convert all words in words_to_check to lowercase for consistency
    words_to_check = [word.lower() for word in words_to_check]
    # 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! 🙂

Updated January 7, 2025: Added additional code to convert list of words to check against to lowercase.

View original
Did this topic help you find an answer to your question?

7 replies

Troy Tessalone
Forum|alt.badge.img+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


  • Author
  • Beginner
  • 1 reply
  • January 10, 2024

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


SamB
Community Manager
Forum|alt.badge.img+11
  • Community Manager
  • 7517 replies
  • Answer
  • January 12, 2024

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: 
40978ffc1e7766c0e3f8d07724416cbc.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"]
    # Convert all words in words_to_check to lowercase for consistency
    words_to_check = [word.lower() for word in words_to_check]
    # 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! 🙂

Updated January 7, 2025: Added additional code to convert list of words to check against to lowercase.


  • New
  • 2 replies
  • January 5, 2025
SamB wrote:

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! 🙂

There is one small typo.

 

check_word function should return word.lower() check, otherwise capitalized keywords might be ignored

>>» return word.lower() in words


SamB
Community Manager
Forum|alt.badge.img+11
  • Community Manager
  • 7517 replies
  • January 6, 2025

Thanks for pointing that out, ​@vbaranov! 🙂

The check_word function should already account for capitalization by converting all the text to lowercase in this line:

words = input_data["text"].lower().split()

I’ve tested the code with capitalized input as well, and it still worked as expected. Can you share an example case where it’s not working? I’d be happy to do some further testing on my end and adjust the code if needed. 

Looking forward to hearing from you!


  • New
  • 2 replies
  • January 6, 2025
SamB wrote:

Thanks for pointing that out, ​@vbaranov! 🙂

The check_word function should already account for capitalization by converting all the text to lowercase in this line:

words = input_data["text"].lower().split()

I’ve tested the code with capitalized input as well, and it still worked as expected. Can you share an example case where it’s not working? I’d be happy to do some further testing on my end and adjust the code if needed. 

Looking forward to hearing from you!

Yep, that is true, but it does not do that for the user-inputted keywords (Banana, Candies, apples, etc).

  1. There could be an instruction mentioning that all keywords in the code should be lowercase
  2. Or to bypass potential user error, just to lower-case of all of user-inputted keywords

SamB
Community Manager
Forum|alt.badge.img+11
  • Community Manager
  • 7517 replies
  • January 7, 2025

Ah, yes I understand what you mean now, ​@vbaranov—thanks for clarifying! 

I’ve updated the code example and corresponding screenshot to help avoid that happening with the user-inputted list of words. Thanks for flagging this and for helping improve the suggested code! 🧡