Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Extract UK Postcode from string

RDF25087
8 - Asteroid

Hi -

 

Apologies, I'm very new to Alteryx and still learning! I have a data source with a list of customer addresses, e.g.

 

Bob Jones Investments Ltd / Rainham RM12 8RS

 

I need to do two things...

 

1. Extract the full postcode to a new column, e.g. RM12 8RS

 

2. Then extract the postcode area to another column, e.g. RM

 

Any help would be greatly appreciated.

 

RDF

6 REPLIES 6
AngelosPachis
16 - Nebula

Hi @RDF25087 ,

 

Do you mind trying the following method and see if that works for you?

 

The workflow uses two RegEx tools, the one to parse out the full postcode and the other to parse the postcode area.

 

Assuming that postcodes in the UK are two string, the first having 2-4 characters and the second string having three characters, I used an expression:

.*\s(\w{2,4} \w{3})

 

That will give you any alphanumeric character that comes after a whitespace, and is consisted out of a first string between 2 and 4 and a second string with 3 alphanumeric characters.

 

AngelosPachis_0-1612785519784.png

 

Parsing the postcode area was easier, as you only want to keep the uppercase letters from the first part of the string.

 

Cheers,

 

Angelos

 

RDF25087
8 - Asteroid

Hi Angelos -

 

I have used your solution below on my data and it seems to work perfectly! I would never have been able to sort that issue out on my own!

 

For my understanding, could you explain how your solution works so I can begin to understand how the formula works?

 

Thanks again

RDF

AngelosPachis
16 - Nebula

Hi @RDF25087 ,

 

The formula works by defining an expression that matches a part of the string you want to parse out.

 

So \w is any alphanumeric character (letter or number) and when you add a { } after that, you define that you are looking for a specific number of alphanumeric characters.

 

\w{2,4} means I'm looking for 2 to 4 alphanumeric characters

\w{3} means I'm looking for exactly 3.

 

Then you place all that inside brackets (), because that's the part of the string you want to parse out, that's the one you want to keep.

 

Finally I have added .*\s before the brackets, because that means that before the group you want to capture, they will be other things (letters, digit, other symbols) followed by a whitespace, but you don't care about those.

 

For the second regex tool, you are looking for two uppercase letters, so that's \u{2}.

 

To learn more about RegEx you can try different resources online that offer you a better intro to Regex from what I just described.

 

Hope that helps 

 

Angelos

RDF25087
8 - Asteroid

Angelos -

 

Thank you for the detailed explanation of how your solution worked. It really is very appreciated. It means that rather than simply accepting a response that works, I can begin to understand the logic and build my own knowledge. So thank you again!

 

RDF

AngelosPachis
16 - Nebula

That's a great attitude @RDF25087  and this is exactly what the community is all about, so all of us can improve our Alteryx skills, one step at a time.

 

Keep it up!

floramavri
5 - Atom

Thank you for sharing this. It's helped me tons!

Labels