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 Text Formula Needed

jboschee
8 - Asteroid

Hi all,

 

Wonder if anyone can help, I have a text string 001_USA_CALIFORNIA_LA_FIRST_ST and I want to be able to extract CALIFORNIA_LA, but also have the ability to apply this to other state/city combinations.

 

 

 

Any help would be appreciated.

 

Thanks

4 REPLIES 4
MarqueeCrew
20 - Arcturus
20 - Arcturus

Regex_replace([field],”.*?_.*?_(.*?_.*?)_.*”,’$1’)

 

that might work.    

 

Cheers,

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
jboschee
8 - Asteroid

Thanks Mark!  That works perfectly.  Can you explain the theory behind it?  I haven't used Regex much.

MarqueeCrew
20 - Arcturus
20 - Arcturus
. Is any character
* is 0 or more
.*_ would be every character until the last underscore in the field.
.*?_ is all characters until the first underscore.

( is the start of a group
) is the end of a group

We looked for the group and ‘$1’ is that group.

<3 regex
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
jboschee
8 - Asteroid

Thanks Mark.  Appreciate the explanation.

Labels