Question

How to recover a text placed between certain words?

  • 8 August 2023
  • 2 replies
  • 19 views

Hello everyone,I want to create a zap allowing me to retrieve the first and last name appearing in the body of an email.I can't figure out why.Here is the body of the email in question:Raw Snippet Interested buyer ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ Interested buyer | Email not displaying correctly? Click here. Octavia Sobczyk is interested in this property €1,160,000 ARCANGUES, 64200I would like to retrieve the first and last name between "click here." and "is interested in this property".Here is the tested code:const bodyText = inputData['1. raw snippet'];const startText = "Click here.";const endText = "interested";const startIndex = bodyText.indexOf(startText) + startText.length;const endIndex = bodyText.indexOf(endText);if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {  const extractedText = bodyText.substring(startIndex, endIndex).trim();    output = {    extractedText: extractedText  };} else {  output = {    extractedText: "Extraction Failed"  };}

 

Thank for your helping.


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Userlevel 7
Badge +12

Hi @Marion DEFONTAINE,

Try changing the following:

bodyText = inputData.keyValue;   //where keyValue is the key for your text

endText = “is interested”;

 

Hope this helps!

Userlevel 7
Badge +14

Hi @Marion DEFONTAINE 

You can try asking ChatGPT to help with your code.

You can also try this Zap action: ChatGPT - Extract Structured Data