Alteryx Designer Desktop Discussions

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

Parse out string after 2nd "-"

wonka1234
10 - Fireball

Hi,

 

Say I have strings like - 

 

4000 - Walmart Retail : NY USA - US-ABC-DE

 

How can I parse this entire column to get this result "US-ABC-DE"?

 

Thanks.

4 REPLIES 4
ChrisTX
15 - Aurora

Use the RegEx tool with this formula: 

 

.*?\-.*?\-\s(.*)

 

This website helps:  https://regex101.com/

 

Chris

 

Rana_Kareem
9 - Comet

Hi @wonka1234 ..

 

Or you can write this expression in Formula Tool:

 

REGEX_Replace([Field Name], ".*-?.*-?\s(.*)", "$1")

 

flying008
14 - Magnetar

Hi, @wonka1234 

 

RegEx formula:

 

 

Trim(REGEX_Replace([Txt], '^[^-]*?-[^-]*?-', ''))

 

If you won't use regex expression: 

 

 

 

Trim(Right(Right([Txt], Length([Txt]) - FindString([Txt], '-') - 1), Length(Right([Txt], Length([Txt]) - FindString([Txt], '-') - 1)) - FindString(Right([Txt], Length([Txt]) - FindString([Txt], '-') - 1), '-') - 1))

 

 

 

录制_2023_09_15_08_57_25_742.gif

caltang
17 - Castor
17 - Castor

If your text is standard, i.e 2-3-2, then you can do something simple like:

(US-[A-Z]{3}-[A-Z]{2})

 

Of course, if it gets more complex, for example, if you have the following strings which are alphanumeric:
4000 - Walmart Retail : NY USA - US-ABC-DE
4000 - Walmart Retail : NY USA - US-sadsad-DE3
4000 - Walmart Retail : NY USA - US-213sdfsad-DeasE

 

You can try:

((?:US[A-Z0-9-]*[A-Z]+-[A-Z0-9-]*[A-Z]+))

 

But if they are non-standard, then the solutions provided by @flying008 @Rana_Kareem @ChrisTX are good to go.

 

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
Labels