Separating address column into multiple columns

I am attempting to use the following formula to extract the four parts of an address and populate the results of each extraction into a separate column:

REGEX.EXTRACT(A2,"[^\n]+,COLUMN(CELL)-1,capture-group-occurrence)

The first part of the address ends in a new line "\n". How do I modify this formula to capture the beginning of the line up to the start of the new line (\n)?

In addition, how to I modify the formula to capture only the state portion separated by spaces.

Here is an image of what I am working with.

Posted on Dec 30, 2024 5:25 PM

Reply
Question marked as Top-ranking reply

Posted on Dec 30, 2024 6:28 PM

Can't say the expressions given below are the best. You might be able to find better elsewhere. They are based on the following rules:

  • Street address is everything before the line feed. It does not include the line feed.
  • City is everything after the line feed and before the comma. The city name can be multiple words. It does not include the line feed or comma.
  • State is all non-digits after the carriage return, town name, comma, and a single space and does not include the single space before the zip code. The state name can be multiple words.
  • ZIP is five digits a dash and 4 more digits at the end of the string or is 5 digits at the end of the string. It tries for 5+4 first.


Extraneous spaces won't cause any harm to extracting the street, city, or state but they will be extracted as part of whichever piece they are in. For instance, you could end up with a city or state that has a trailing space character. You can put TRIM(...) around the formulas to strip off any extraneous leading, trailing, and repeated spaces within the strings.




Street C2=REGEX.EXTRACT(B2,".+(?=\n)")

City D2=REGEX.EXTRACT(B2,"(?<=\n).+(?=,)")

State E2=REGEX.EXTRACT(B2,"(?<=\n"&D2&", )\D+(?= )")

ZIP F2=REGEX.EXTRACT(B2,"(\d{5}-\d{4})|(\d{5})")



2 replies
Question marked as Top-ranking reply

Dec 30, 2024 6:28 PM in response to Don Parsley

Can't say the expressions given below are the best. You might be able to find better elsewhere. They are based on the following rules:

  • Street address is everything before the line feed. It does not include the line feed.
  • City is everything after the line feed and before the comma. The city name can be multiple words. It does not include the line feed or comma.
  • State is all non-digits after the carriage return, town name, comma, and a single space and does not include the single space before the zip code. The state name can be multiple words.
  • ZIP is five digits a dash and 4 more digits at the end of the string or is 5 digits at the end of the string. It tries for 5+4 first.


Extraneous spaces won't cause any harm to extracting the street, city, or state but they will be extracted as part of whichever piece they are in. For instance, you could end up with a city or state that has a trailing space character. You can put TRIM(...) around the formulas to strip off any extraneous leading, trailing, and repeated spaces within the strings.




Street C2=REGEX.EXTRACT(B2,".+(?=\n)")

City D2=REGEX.EXTRACT(B2,"(?<=\n).+(?=,)")

State E2=REGEX.EXTRACT(B2,"(?<=\n"&D2&", )\D+(?= )")

ZIP F2=REGEX.EXTRACT(B2,"(\d{5}-\d{4})|(\d{5})")



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Separating address column into multiple columns

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.