# How to get state from address

**URL:** <https://community.glideapps.com/t/how-to-get-state-from-address/81341>\
**Category:** Ask for Help\
**Created:** [April 14, 2025, 8:52pm UTC](https://community.glideapps.com/t/how-to-get-state-from-address/81341 "2025-04-14T20:52:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanp](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@ryanp](https://community.glideapps.com/u/ryanp)\
**Post date:** [April 14, 2025, 8:52pm UTC](https://community.glideapps.com/t/how-to-get-state-from-address/81341/1 "2025-04-14T20:52:14Z")

</div>

hello, im looking for help to pull just the state from an address i have address being verified by google and have complete address in a db but cant seem to pull out just the abbreviated state? any help would be great!

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 15, 2025, 12:32am UTC](https://community.glideapps.com/t/how-to-get-state-from-address/81341/2 "2025-04-15T00:32:02Z")

</div>

Sample data:

| # | Address | Expected State |
| --- | --- | --- |
| 1 | 123 Main St, Anytown, CA 90210 | CA |
| 2 | 456 Oak Avenue, Springfield, IL 62704-5678 | IL |
| 3 | 789 Pine Ln Smallville NY 10001 | NY |
| 4 | PO Box 100 Somewhere AZ 85001-9999 | AZ |
| 5 | 1600 Pennsylvania Avenue NW, Washington, DC 20500 | DC |
| 6 | 1 Mountain Rd, Boulder , CO 80302 | CO |
| 7 | Unit NV, 100 Casino Way, Las Vegas, NV 89109 | NV |
| 8 | 1 Apple Park Way, Cupertino, California 95014 | null |
| 9 | 1 Canada Way, Ottawa, ON K1A 0A9 | null |
| 10 | 10 Downing St, London | null |

Actual implementation with a JavaScript column, address being p1.

 ![CleanShot 2025-04-15 at 07.32.43@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/c/5/c530ac4a06fc28c318d81a47588fc9e8dfbd8158.png)

```auto
function extractStateAbbreviation(addressString) {
  if (!addressString || typeof addressString !== 'string') {
    return null;
  }

  const regex = /,\s*([A-Z]{2})\s+\d{5}(-\d{4})?\s*$/;
  const match = addressString.match(regex);

  if (match && match[1]) {
    return match[1];
  }

  const regexNoComma = /\b([A-Z]{2})\s+\d{5}(-\d{4})?\s*$/;
  const matchNoComma = addressString.match(regexNoComma);
   if (matchNoComma && matchNoComma[1]) {
     const potentialStateIndex = matchNoComma.index;
     if (potentialStateIndex > 0) {
        const charBefore = addressString[potentialStateIndex-1];
        if (charBefore === ' ' || charBefore === ',') {
             return matchNoComma[1];
        }
     }
  }

  return "";
}

return extractStateAbbreviation(p1)

```

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 15, 2025, 12:37am UTC](https://community.glideapps.com/t/how-to-get-state-from-address/81341/3 "2025-04-15T00:37:29Z")

</div>

What the function does (and it relies on you having a ZIP code in the address, it can return false positives if we adjust the function to not require the ZIP code though):

- First, it quickly checks if you actually gave it an address string. If the input is empty, missing, or not text at all, it immediately stops and returns null (which basically means “I couldn’t find anything”).

**The Main Search (Looking for “, ST ZIP”):**

- It then uses a specific search pattern (this is the regex part) designed to find the most common way a state appears in a US address.

- It looks for this sequence **near the end** of the address string:

- If it finds this exact pattern, it **grabs those two uppercase letters** it found and returns them as the result.

**The Backup Search (Looking for " ST ZIP" without a comma):**

- If the first search didn’t find anything (maybe the address was formatted like “Anytown ST 12345” without a comma before the state), it tries a second, slightly different search pattern.

- This pattern looks for:

- **Extra Check:** If it finds this pattern, it does one small extra check: it looks at the character immediately before the two letters it found. If that character is a space or a comma, it’s more confident that it actually found the state (and not just two letters that happen to be at the end of the city name). If this check passes, it returns the two letters.

---

<div class="post-metadata">

**Author:** ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)\
**Post date:** [April 15, 2025, 8:08am UTC](https://community.glideapps.com/t/how-to-get-state-from-address/81341/4 "2025-04-15T08:08:05Z")

</div>

Using Glide computed columns only (without using JavaScript).

I never have to deal with such cases, but I would attempt to approach the problem as follows:

1. I would split the address using the comma as a delimiter.
2. I would assume that the state abbreviation was in the last element of the array, so maybe depending on the number of elements I would try to isolate the last element or remove the first ones. I’m not sure I’d be able to achieve this, but possibly.
3. I might have to convert the array to text and then I’d remove any trailing spaces at the beginning and end.
4. I’d split again using space as the delimiter.
5. I would assume that the state abbreviation would be the first element of the array. And just like previously I would try to isolate it.

In the experimental columns there is a group of columns to work with arrays. Those would come in handy.

 ![Screenshot 2025-04-15 at 10.11.25](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/5/a584cc864b7a2d978b76e7e1134d805c627f46de.jpeg)

There are a few assumptions here on the position of the abbreviation. I suppose there could be a final verification to assess the length of the resulting string. If \>3, then it would not be the state abbreviation.

This is how I would approach it. I’m not saying it’s a good way, but it could be a way.
