Skip to main content
Best answer

Finding specific text from a list?

  • 20 August 2024
  • 3 replies
  • 15 views

Hey, wondering if there’s a simple solution to this. I have some text in my trigger that I want to check for specific keywords. Let’s say the text could be “asdf London”, “dfghd Paris” or “asdfsdf New York”.

 

What I want to do is extract “London” “Paris” or “New York” from the text. There’ll only ever be one of these keywords included in each submission. Is there a way to do this simply? There’s only going to be a handful of these keywords (about ten) so in theory I think I could make 10 formatter modules (?) but wondering if there’s a better way. 

Hi @oli 

Most efficient, but advanced approach, would be to use a Code step:

https://zapier.com/apps/code/help

 

Try using the AI helper to generate the Code:

https://help.zapier.com/hc/en-us/articles/15666688064013-Generate-a-Code-step-using-AI-Beta

 

Or try using ChatGPT to generate the Code.


Hi there @oli 👋

Were you able to get this up and running using a Code action as Troy suggested? 

Let us know if you’re still stuck at all on this - happy to assist further! 🙂


Thanks @Troy Tessalone, appreciate the steer! I used Zapier’s built in AI tool and it seems to be working with some light testing. Will report back if I find any errors when it’s being used for real. 


const text = inputData.text || '';

// Use a regular expression to find "Dundee" or "Edinburgh" in the text
const match = text.match(/Dundee|Edinburgh|Inverness/);

// Prepare the output based on whether a match was found
if (match) {
output = { city: matchm0] }; // Return the matched city
} else {
output = {}; // Return an empty object if no match is found
}

 


Reply