Conditional Actions: Check if the field contains any of multiple words
Hi,
I would like to account for different words in my Message field. I want to know if it contains any of "United States", "USA", "US". How do I do this? I understand that I can divide them into multiple conditions, but I would prefer to keep it in a single formula.
Best Answer
P
Patricia Guevarra
said
over 5 years ago
Hi Saul,
Thanks for reaching out! Please try the following formula:
Saul Macht
Conditional Actions: Check if the field contains any of multiple words
Hi,
I would like to account for different words in my Message field. I want to know if it contains any of "United States", "USA", "US". How do I do this? I understand that I can divide them into multiple conditions, but I would prefer to keep it in a single formula.
Hi Saul,
Thanks for reaching out! Please try the following formula:
Message.scan(/(United States)|(USA)|(US)/).present?
where Message is your data pill.
Let me explain this formula step by step.
1. The .scan formula checks if the field has any of the specified values and returns them as an array or as a list.
2. The .present? formula checks if the scan retrieved any matching values and will return "true" or "false" accordingly.
Patricia Guevarra
Hi Saul,
Thanks for reaching out! Please try the following formula:
Message.scan(/(United States)|(USA)|(US)/).present?
where Message is your data pill.
Let me explain this formula step by step.
1. The .scan formula checks if the field has any of the specified values and returns them as an array or as a list.
2. The .present? formula checks if the scan retrieved any matching values and will return "true" or "false" accordingly.
Amanda Wong
Hi Saul,
You can also use the .include? formula to help you evaluate that e.g.
["US","USA","United States"].include?(Message)
Do note that only exact matches (case-sensitive) would evaluate to true.