In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests after December 31, 2025. Set up your security questions now so you can recover your account anytime, just log out and back in to get started. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Regex to Parse City State

hellyars
13 - Pulsar

Regex question.  I have city and state in a single field.  The comma is NOT always present, so I can't use that as a delimiter. City names can be 1-2 part names. State names are always 2-3 uppercase characters.

How can I regex this.

 

I need to use a parse tool.  This regex expression does not work:  ^.*?[A-Z]+

 

 

Field1CityState
Larapinta, Brisbane, QLDLarapinta BrisbaneQLD
Blacktown Sydney NSWBlacktown SydneyNSW
Coomera QLDCoomeraQLD
Manly Vale NSWManly ValeNSW
Wingfield SAWingfieldSA
2 REPLIES 2
PhilipMannering
16 - Nebula
16 - Nebula

You could use,

 

 

(.*),? (\u+)

 

 

in the Regex Tool (Parse Method). I believe that will do the trick. 

PhilipMannering
16 - Nebula
16 - Nebula

Incidentally, your regex patter would have worked too if you add some parentheses and a $ sign.

^(.*?) ([A-Z]+)$

hen you Parse you always need to have a set of brackets to show what you're capturing. In the case above you're capturing everything up until a space and also capital letters at the end of your string. Don't forget to heed the case sensitivity checkbox.

Labels
Top Solution Authors