Alteryx Designer Desktop Discussions

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

Extracting Data from Inside a Parentheses

crazybeauti_ful
8 - Asteroid

Hi,

 

How do I extract 'Belgium' from 'BE (Belgium)'?

 

I looked for solutions here but somehow, I am only getting 'BE' as output.

 

Thank you.

 

11 REPLIES 11
grossal
15 - Aurora
15 - Aurora

Hi @crazybeauti_ful,

 

can you explain the wider context? Do you always want to extract what is inside two brackets? Or do you always want to get the word Belgium? Can you provide a minimal sample?

 

If you can't provide a sample, here are some things you might want to look for: Regex and Formula.

 

Best

Alex

AbhilashR
15 - Aurora
15 - Aurora

Hi @crazybeauti_ful, you could use the regex tool and construct relevant Regex expression to parse out the text between brackets. Attached is a sample to help you get started and expand upon.

crazybeauti_ful
8 - Asteroid

Hi @grossal , I need to always get the data inside the parenthesis. I did try regex but I only got either the first 2 letters (outside the parenthesis) or 0.

grossal
15 - Aurora
15 - Aurora

HI @crazybeauti_ful,

 

here is a Regex to achieve it. It's a bit tricky because you have to escape the parenthesis and use them in order to catch it.

 

grossal_0-1585773755372.png

Output:

grossal_2-1585773786602.png

 

 

 

Regex:

 

grossal_1-1585773779172.png

 

Regex-Code for easy copy paste:

 

.*\((.*)\).*

 

Workflow attached. Let me know if it works for you!

 

 

Best

Alex 

dannyg
5 - Atom

Hi,

 

I took a different approach, I used text to columns and used the ( as my delimiter. Then I used a formula to remove the other ) and that would just leave me with the text inside the parentheses. See the attached file and let me know if it works.

DavidP
17 - Castor
17 - Castor

I like your thinking @dannyg !

RogersGraceC
5 - Atom

Can someone explain the syntax for the solution, please?

.*\((.*)\).*

With all the parentheses I'm having trouble understanding the different pieces of it. Thanks!

Rob48
8 - Asteroid

Would love to have this formula saved somewhere but RegEx doesn't have that option.  how would you wite this out for the Multi-Field Formula tool (where I can save the expression)?

 

PS - why don't the other formula-based tools have the ability to save expressions?  I use the Multi-Field tool in cases where I could just as easily use a Formula tool only because I've got the expression I need save there.   

dwstada
10 - Fireball

@Rob48  this would be the formula for a column called "Field" :REGEX_Replace([Field], ".*\((.*)\).*", "$1")

 

it replaces the whole expression with the first capture group (a capture group is what is in () and $1 calls back to the first capture group), which would be Belgium in this case

Labels