Best answer

Formatter: find multiple of same pattern

  • 30 December 2022
  • 8 replies
  • 282 views

Userlevel 1

Hey everyone! First time poster, long-time user of Zapier. I’m looking for help finding multiple instances of 1 pattern within Gmail: https://cdn.zappy.app/280b36151a33b4023af6ef12eb6851a9.png

At the moment I can only find the first instance — “Image 3884172” — but none after. Support didn’t have an answer and suggested this forum. Here’s an overview of my Zap setup:

  1. New Gmail
  2. Filter by sender (...@stocksy.com)
  3. Formatter 1: Split text (find “Image[:space:]”)
  4. Formatter 2: Split text (find the number after (e.g. 3884172)
  5. Send date of email and result (e.g. Image 3884172) to Slack
  6. Send date of email and result (e.g. Image 3884172) to Google doc

Example of what it looks like in Slack:
https://cdn.zappy.app/68e7203daa4206da3cabbacca4a01768.png

 

Does this make sense? If so, how might I accomplish this? I’ve messed around with Looping and the “count” within Formatter but it doesn’t work. Thanks! 

 

icon

Best answer by RALaBarge 4 January 2023, 16:18

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.

8 replies

Userlevel 7
Badge +12

Hmm, I wonder if there’s a way of achieving this using a code step. 

@Troy Tessalone I know that you’re a wiz with parsing data using code, do you have any ideas?

 

Thanks!

Userlevel 7
Badge +14

Hi @jonaschafer 

Good question.

Try using a robust email parsing app such as Mailparser: https://zapier.com/apps/mailparser/integrations

Userlevel 1

Thanks @Danvers! @Troy Tessalone OMG that’s brilliant and I’m mad I didn’t think of it. Will try out, thanks! 

Userlevel 1

@Troy Tessalone — Follow up question: I set up a new mailbox, forwarded an email to it, and created a template. Here’s a screenshot that points to the top 2 parsed patterns, and the email template to the right. I would just need to remove “Image[:space:]” for this to work, pretty easy. 

 

But here’s my question: the number following “Image[:space:]” is going to change, and the quantity of that pattern (in this screenshot, there are 4) is also going to change. For example: one email might be just 1 pattern “Image 12345678” while another email might have 10. So how do I set up the email parser template to account for this? 

Userlevel 4
Badge +7

Hey there, looks like there are a lot of good ideas here thus far.  Here is another one involving Regular Expressions:

 

Zap Editor Input for Extract Pattern

Just doing a bit of a quick and dirty test here with my input data, we can use RegEx to match whatever strings we want here with the pattern of:

(image\s\d{3})\s

To break this down a little bit:

  • The \s represents a space character
  • The \d represents any digit character
  • The {3} says I want 3 of the previous character in a row
  • ...and the ( ) around the entire thing is called a Grouping which says “Give me these as output”

Here is our output:

 

Regular Expressions are one of the most powerful concepts in computers, something that is used across many programming languages, and is relatively consistent with regards to the patterns which are accepted across said languages.

In the case of your data, it looks like there would be 7 possible numbers in your Image strings you want to grab, so you would replace my 3 with 7 in the pattern shared above.  

Check out more about RegEx here: https://regexlearn.com/

Userlevel 1

@RALaBarge That worked beautifully! Now the Zap is just down to 2 steps, love the simplicity. 
 

Follow up: I was able to pluck out the pattern and the all instances (screenshot) but haven’t found a way to remove “Image[:space:]” before the number, and splitting each # onto it’s own line. I tried Formatter/Split text and used “Image[:space:]” as the Separator but it returns blank data. 

The end goal is to have each URL to end with just the number, but right now it’s a URL with all the data: 

https://cdn.zappy.app/ba7fdb070a05440f2e285ce9d80928db.png

Userlevel 4
Badge +7

Hey again @jonaschafer!

Roger that, if you JUST needed the numbers and not the “Image” bit, you could modify your RegEx a bit to put the groupings around the numbers.  If your string is:

image 1234567 - bla bla bla.  Image 1234568 - blab blab blab ...

And if you just want the 1234567 your pattern could be:

image\s(\d{7})\s

I still keep the image string in my pattern to tell RegEx to expect this, to give it context as to where I want the 7 digits to be pulled from.  I put my grouping around the digits only and this would give you an output of JUST digits.

This would leave you with a line item object of numbers...if you then needed to append them each to a URL, since it is a line item object you would need to either use Looping by Zapier or Google Sheets Make Multiple Rows or something that natively accepts our Line Item objects (as denoted by the description of the action in the Zap Editor). 

 

Lets think about the Google Sheets method, your Zap could look like so:

Email Trigger => Formatter by Zapier Match Pattern => Google Sheets Make Multiple Rows

 

For the GSheets step, you would type in the base URL in a row and then map the output from the Line Item object after it, like you did above.  This time we should just have a bunch of numbers to give you, and the GSheets step will make 1 URL from each number you give it in their own row.

That would let you generate those URLs individually and drop them into a sheet.  From there you could have a 2nd Zap triggering off of New Rows to this new sheet to trigger off of each URL and then you can do whatever you want individually with them.

Let me know how it goes! =)

Userlevel 1

@RALaBarge That’s so elegant! I set everything up, turned it on and am waiting to see how it works. Thanks for the detailed guidance and swift RegEx formula! ❤️