Formatter extracting 12-digit strings as intended, but unable to convert into line items

  • 20 February 2024
  • 2 replies

Hello all,

Thanks in advance for the help!

I have a Gmail → Formatter → Sheets zap set up to: Extract (varying quantity of) multiple 12-digit numbers from the e-mail body, then updating the sheets with multiple rows. While i was able to successfully extract the 12-digit strings as multiple items, it does not return as line items - this is an issue because of the varying quantity of 12-digit strings that the e-mail body might contain.

I recently was successful in extracting 5 sets of numbers, and individually inputting the 5 sets of numbers as multiple rows on the sheet. But it limits me to 5 sets of numbers for the zap, while i may potentially have (varying) 1 to 40 sets of 12-digit numbers on a single e-mail body; this method also creates 5 similar rows on the sheet if the e-mail body has only 1 set 12-digit strings.

I’m not sure how i could make the initial (transform) extraction return as line items.


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

Thought this might be important: The formatter returns these. The _end, _matched & _start seemingly seemed to be able to return as line items - only need to input a single output into the sheets data, and it will return as 5 separate lines.


Userlevel 7
Badge +11

Hi there @consignscc

Ah yes, I did some testing just now and can see what you mean about the output from the Formatter action. Hmm, in order to have a varying number of 12 digit numbers extracted I think your best bet may be to handle it in a Code by Zapier action instead of using Formatter. 

I did some playing around and was able to get a list of all 12 digit numbers, extracted from some text using the following setup:

This output them into a field called Numbers:

Here’s the code that you can copy and paste into the Code action if you’d like to give this a try:

import re
email = input_data['emailText']
match = re.findall(r'\b\d{12}\b', email)

if match:
return [{'Numbers': match}]

From there, in a Create Multiple Spreadsheet Rows action you can select the Numbers field that’s output by the Code action and that will allow it create multiple Spreadsheet rows, for each of the different numbers that were extracted.

If helpful you can learn more about how to use Python Code actions here:

Hope that helps. If I’ve misunderstood the end goal here or you run into any issues on that just let me know!