Best answer

Need help capturing text from Gmail body using regex

  • 4 February 2023
  • 6 replies
  • 180 views

Userlevel 1

I have regular emails in which the body has the following format:

 

Hi JOE SMITH,

ANDY JOHNSON has sent you $90.00 (CAD) and the money has been automatically deposited into your bank account at ABC Financial.

 

I have the process set-up, the email trigger works etc. the only step I need to figure out is getting the amount (90.00) extracted into a new row in a Google Sheet, and I am having a challenge with the regex to capture the 90.00.

Sometimes it’s 5 digits (instead of 90.00, it might be 550.00, etc.) and I need to ensure it can capture up to the 6 characters, three digits + period + two digits.

 

Thank you kindly for any help with this!!

icon

Best answer by CatsAndDucks 6 February 2023, 17:21

View original

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

6 replies

Userlevel 7
Badge +14

Hi @CatsAndDucks 

Good question.

Here’s what ChatGPT by OpenAI provided:

 

Userlevel 1

Thank you! One more thing I would like is how to extract the name which would be at the beginning of the second paragraph of the body:

 

Hi JOE SMITH,

ANDY JOHNSON has sent you $90.00 (CAD) and the money has been automatically deposited into your bank account at ABC Financial.

 

So I would want “ANDY JOHNSON” and again this could be ANDY EDWARD JOHNSON so 2-4 words. I have tried loading ChatGPT but it says servers are at capacity so I cannot access it. Thank you for your help!

Userlevel 7
Badge +14

@CatsAndDucks

For the name, try using a Formatter > Text > Split

e.g. split (“ has sent”) and keep the first segment.

 

FYI: 1 Code step could be used to replace the multiple Formatter steps.

 

let Set = inputData.Set;
let Amount = Set.split("$")[1].split(" ")[0];
let Name = Set.split(",")[1].split(" has sent")[0].trim();

output = [{Amount, Name, Set}];

 

 

Userlevel 1

Thank you! Is there any way to use Zapier to extract from emails already sitting in my Gmail? So not for upcoming ones as they arrive, but if I had a label “transfers” and wanted Zapier to run a zap on all of them.

Userlevel 7
Badge +14

@CatsAndDucks 

These are the available Gmail Zap triggers:

 

Not all my emails are triggering my Zap

Each Gmail trigger has a specific length of time in the past that it can "see" emails in your Gmail account. If the email in question is older than the time limit, the trigger won't be able to detect that email.

These limits are as follows:

  • New Labeled Email - Unlimited
  • New Starred Email - 2 days
  • New Email - 1 hour
  • New Email Matching Search - 1 hour
  • New Thread - 1 hour
  • New Attachment - 1 hour

Please note that if you would like to trigger a Zap for starred emails that entered your inbox more than two days ago, you can use the New Labeled Email trigger and specify the STARRED label from the dropdown when setting up your Zap.

Userlevel 1

Tremendous! The “New Labeled Email” is perfect, you have been a massive help and I can’t thank you enough!