Skip to main content
Best answer

How to extract and separate address info from Jotform responses?

  • 24 June 2024
  • 2 replies
  • 18 views

This post has been edited by a moderator to remove personal information. Please remember that this is a public forum and to remove any sensitive information prior to posting.

How do I extract that information from Jotform?

I have a question on Jotform that uses Google Address Validation. The address returns the following line item on text format:
Street name: Little xxxxxxx House number: x/xx City: xxxxxxx North State: VIC Postal code: xxxx Country: xxxxxxxx

I want to separate the information into Street Name, House Number, City, State, Postal code, Country.

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 +14

This post has been edited by a moderator to remove personal information. Please remember that this is a public forum and to remove any sensitive information prior to posting.

Hi @medicalpantry 

That can be done with multiple Formatter > Text steps or 1 Code step.

 

You can ask AI in the Zap Code step to generate the code to use: https://help.zapier.com/hc/en-us/articles/15666688064013-Generate-a-Code-step-using-AI-Beta

 

For reference, JavaScript from ChatGPT:

 

const address = "Street name: Little xxxxxxxx House number: 9/47 City: xxxxxx North State: VIC Postal code: xxxx Country: x";xxxxx

// Regular expressions to match each part of the address
const streetNameRegex = /Street name: (.*?) House number:/;
const houseNumberRegex = /House number: (.*?) City:/;
const cityRegex = /City: (.*?) State:/;
const stateRegex = /State: (.*?) Postal code:/;
const postalCodeRegex = /Postal code: (.*?) Country:/;
const countryRegex = /Country: (.*)/;

// Function to extract address component using regex
const extractComponent = (regex, text) => {
    const match = text.match(regex);
    return match ? match[1].trim() : null;
};

// Extracting each component
const streetName = extractComponent(streetNameRegex, address);
const houseNumber = extractComponent(houseNumberRegex, address);
const city = extractComponent(cityRegex, address);
const state = extractComponent(stateRegex, address);
const postalCode = extractComponent(postalCodeRegex, address);
const country = extractComponent(countryRegex, address);

// Output the extracted values
console.log("Street Name:", streetName);
console.log("House Number:", houseNumber);
console.log("City:", city);
console.log("State:", state);
console.log("Postal Code:", postalCode);
console.log("Country:", country);

output = {
    streetName: streetName,
    houseNumber: houseNumber,
    city: city,
    state: state,
    postalCode: postalCode,
    country: country
};

 

Userlevel 1

Thanks Troy! That was amazing!

 

This post has been edited by a moderator to remove personal information. Please remember that this is a public forum and to remove any sensitive information prior to posting.

Hi @medicalpantry 

That can be done with multiple Formatter > Text steps or 1 Code step.

 

You can ask AI in the Zap Code step to generate the code to use: https://help.zapier.com/hc/en-us/articles/15666688064013-Generate-a-Code-step-using-AI-Beta

 

For reference, JavaScript from ChatGPT:

 

const address = "Street name: Little xxxxxxxx House number: 9/47 City: xxxxxx North State: VIC Postal code: xxxx Country: x";xxxxx

// Regular expressions to match each part of the address
const streetNameRegex = /Street name: (.*?) House number:/;
const houseNumberRegex = /House number: (.*?) City:/;
const cityRegex = /City: (.*?) State:/;
const stateRegex = /State: (.*?) Postal code:/;
const postalCodeRegex = /Postal code: (.*?) Country:/;
const countryRegex = /Country: (.*)/;

// Function to extract address component using regex
const extractComponent = (regex, text) => {
    const match = text.match(regex);
    return match ? match[1].trim() : null;
};

// Extracting each component
const streetName = extractComponent(streetNameRegex, address);
const houseNumber = extractComponent(houseNumberRegex, address);
const city = extractComponent(cityRegex, address);
const state = extractComponent(stateRegex, address);
const postalCode = extractComponent(postalCodeRegex, address);
const country = extractComponent(countryRegex, address);

// Output the extracted values
console.log("Street Name:", streetName);
console.log("House Number:", houseNumber);
console.log("City:", city);
console.log("State:", state);
console.log("Postal Code:", postalCode);
console.log("Country:", country);

output = {
    streetName: streetName,
    houseNumber: houseNumber,
    city: city,
    state: state,
    postalCode: postalCode,
    country: country
};