Question

How to extract specific data (like address) from a text field in Zapier?

  • 22 February 2024
  • 16 replies
  • 207 views

Badge

Hi,

 

I have a zap which gets address information but is nested in a message format with other contact details.  I would like to extract the address from the text only.  The text is provided in the following format;

 

Name: Ellie Bloggs Company: Test Company Call back number: 020 87206495Email: etomnay@test.comAddress: 6 Test Street, London, E1 2LACall regarding: She would like a drone roof survey at one of their properties as they would like to highlight repairs needed. She said that it is a four or five storey property with very limited roof access

Does anyone know how this can be achieved?


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

16 replies

Userlevel 7
Badge +11

Great question @BradE! 🙂

Is the text provided in an email? If so, then you could forward those emails to an Email Parser mailbox and it would parse out the text in the email into separate fields that you could then select in your Zap. You can learn more about that here: Trigger Zaps from new parsed emails

If it’s not from an email then you could use a Formatter (Text > Extract Pattern) action to extract the text that appears between “Address:” and “Call regarding:”. See Extracting Text From in Between Specific Values for details on how to do that. 

Would either of those options work for your needs here?

Userlevel 7
Badge +14

Hi @BradE 

Here’s an approach…

Action: Formatter > Text > Split

Split by “Address: ”

Keep the Last Segment

 

Action: Formatter > Text > Split

Split by “Call regarding:”

Keep the First Segment

Badge

Hi - thanks for your reply...so I managed to get the address extracted from the text.  See attached. 

 

However, my final question is how do I get the Address (i.e. street address, city, county) separated from the postcode.  The reason I need them separated into different variables for use later on in my Zap is because they are being entered into a CRM which takes the address on multiple lines and the postcode is a separate field. 

The thing that is confusing me is street address can be 1, 2, 3 or even 4 lines sometimes, so I need the code to be able to cope with variations in address length.  The postcode is always last in the string, so I did think of splitting the string by comma and pick from list to get the last line item.  This would presumably work for the postcode, but what about the rest of the address?

Any help is much appreciated!

 

 

Userlevel 7
Badge +14

@BradE 

Action: Formatter > Text > Split

Split by comma

Return as separate fields

 

NOTE: If the Address is not consistently formatted, then the output results will vary and may lead to invalid values and errors in following Zap steps

Badge

Hi Troy,

Sorry, I wasn’t very clear in my question.  I would like to format the above example output like so:

 

$address variable:

5 Mercer Walk
London

 

$postcode variable:

WC2H 9QB

 

is this possible?

 

Userlevel 7
Badge +14

@BradE 

Give this a try…

In your example, it should output 3 variables, then you can combine those together how you’d like in the following Zap steps.

 

Action: Formatter > Text > Split

Split by comma

Return as separate fields

 

NOTE: If the Address is not consistently formatted, then the output results will vary and may lead to invalid values and errors in following Zap steps

Badge

Is there a formatter utility to combine all of the line items except for the last line item (i.e. the postcode)

Userlevel 7
Badge +14

@BradE 

You can use this previous suggestion to remove the last line item.

 

Action: Formatter > Text > Split

Split by “Call regarding:”

Keep the First Segment

Badge

Hi Troy,

In my example i get 3 separate variables and you’re correct I can use each variable in my following Zaps.  This works fine. 

However, what if the address outputs 4 variables?  This will happen when the address has 4 lines, for example:

Street line1, street line 2, city, county, postcode

Userlevel 7
Badge +14

@BradE 

Yep, I cautioned about this previously.

Parsing a full address can be tricky due to the possible address variations.

 

NOTE: If the Address is not consistently formatted, then the output results will vary and may lead to invalid values and errors in following Zap steps

Badge

I see 🤔

Tricky or not possible?

My logic would go something like this:

  • Step 1 - Extract address from text using split as per above
  • Step 2 - Convert the address to line items
  • Step 3 - Use choose from list (last item) to get the postcode

This is where I get stuck…

  • Step 4 - Remove the postcode from Step 2 line items (how do I do this in formatter)
  • Step 5 - Use line items to text using separator \n

Would this logic work?

 

Userlevel 7
Badge +14

@BradE 

Action: Formatter > Text > Replace

Badge

Hi Troy,

I managed to get the Zap working as it should. The only issue is when I use the Formatter » Line item to text with the [:newline:] or [:return:] separators it puts in an extra space on the second and third items…what is the reasoning behind this? Is there any easy fix?

Userlevel 7
Badge +14

@BradE 

We would need to see screenshots to have more context.

Badge

Hi,

 

Please see attached screenshots.

 

 

 

 

 

There is an extra space before London for some reason?

 

Userlevel 7
Badge +14

@BradE 

You can try adding another Formatter step to remove whitespace.