Missed the Q4 Fall Release Product Update? Watch the on-demand webinar for more info on the latest in Designer 24.2, Auto Insights Magic Reports, and more!
Free Trial

Alteryx Designer Desktop Discussions

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

Remove everything except what is in parentheses?

pacbloyd
7 - Meteor

How would I convert something like 'US (United States)' to just 'United States' ? Have to do this for multiple countries

10 REPLIES 10
Thableaus
17 - Castor
17 - Castor

Hi @pacbloyd could the row have more than one "string between parenthesis" occurence?

pacbloyd
7 - Meteor

Hello @Thableaus - I don't think so. I just need to do this for many countries where there's an abbreviation before the full country name in parentheses.

 

What about a solution which simply trims off the first 4 characters (i.e. the 2 letter abbreviation, space, and opening parentheses, and then another formula to trim off the last character (i.e. the closing parentheses)?

pacbloyd
7 - Meteor

I think I figured it out using a right and left function:

 

right([Country],Length([Country])-4)

 

left([Country],Length([Country])-1)

 

However, if there is a better formula, or a formula that extracts from parentheses, let me know

Thableaus
17 - Castor
17 - Castor

@pacbloyd 


REGEX in tokenize mode to split only what you need:

 

Thableaus_0-1642623241714.png

 

 

Expression: \([^()]+\)

 

 

\( - open parenthesis

[^()]+ capture everything that is not an open/closing parenthesis

\) - closing parenthesis

 

I think that might work.

Thableaus
17 - Castor
17 - Castor

I'm sorry, if you don't wanna catch the parenthesis as well, you could use "unmarked groups".

 

(?:\()([^()]+)(?:\))

 

add ?: before open/closing parenthesis character.

 

Thableaus_1-1642623501547.png

 

Thableaus
17 - Castor
17 - Castor

The nice thing about using Tokenize that it's dynamic enough to grab multiple occurences.

 

Thableaus_2-1642623626954.png

 

 

That's for example if I had 3 instances of the same pattern. And if you want to make even more dynamic you could use Tokenize and Split to Rows, so you dont have to specify a number of columns.

binuacs
21 - Polaris

@pacbloyd another option using RegExReplace formula

 

binuacs_0-1642623742159.png

 

pacbloyd
7 - Meteor

Thank you, @binuacs !

 

Bonus question, how would I do the same, but for brackets instead of parentheses?

binuacs
21 - Polaris

@pacbloyd the below RegEx formula remove both ( and [ from the country name

 

REGEX_Replace([Country], '(.+?)[\(\[](.+?)[\)\]]', '$2')

 

binuacs_0-1642629283995.png

 

Labels
Top Solution Authors