We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Getting a code from a string

Sammy22
8 - Asteroid

hello,

 

i have a field which is in the format below. i need to take the code from these fields which is always in the middle after the country name, it is always 9 characters long and starts with either a G or 1.  Any easy way to do this?

 

BreadFrance103A01D88Bakery 1
PastaItalyG01004375Foods
EggsUnited KingdomG01004375Fresh F
6 REPLIES 6
JosephSerpis
17 - Castor
17 - Castor

Hi @Sammy22 one approach would be to use regex. The following Regex will first look for 1 or G then return 8 more characters I also unticked the case insenstive so I don't get a lower case g like in the third row.

 

Regex_30112021.JPG

Sammy22
8 - Asteroid

This works almost but if there is another 1 or g before the code then it won't work for example if i have the below scenario.

 

TeaGermanyG12345678Drinks

JosephSerpis
17 - Castor
17 - Castor

Hi @Sammy22 updated the regex to look for numbers and captial letters after it finds 1 or G.

 

Regex_30112021.JPG

Sammy22
8 - Asteroid

This is great thank you! could you explain the expression to me as i have not used regex before please?

Pingu
10 - Fireball

Is it possible you explain the two regex functions in words and the difference between them exactly? Trying to learn regex more... But I don't understand how this now still works even when countries contain a G. Thank you!

JosephSerpis
17 - Castor
17 - Castor

So first of Im using the parse method to extract the pattern I want to match into a new colmun. ([1G][A-Z0-9]{8}) The brackets () represent the entire pattern I want to parse. [1G] means look for either 1 or captial G then [A-Z0-9]{8} means looks for characters between A-Z captalised and 0-9 for 8 characters. 

Labels
Top Solution Authors