Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Removal of certain parenthesis

georgehenry
5 - Atom

(Td-234) this is the text we keep (dont need to remove)

(Ta-546) hello (ba vg) in this cass

 

 

so in the example above of two strings trying to remove both first parentheses and its text. I have used regex replace but it removes all parthesis while i want to remove only first one and its text. Please help 

 

9 REPLIES 9
caltang
17 - Castor
17 - Castor

Can you provide more sample data and expand on your ask? Quite confused, and I’m not clear exactly what you want.

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
georgehenry
5 - Atom

So for example please find it below:

 

 

This is how the field looks like

(TD-123)  General Marchandise - store (rev c)

(TD-135)  General Marchandise - store (rev c) marchandise - night version

 

So in this case what i need to is get rid if (TD-123) in first row and (TD-135), So the ask is remove the parthesis and data within. 

jdminton
12 - Quasar

You can use the substring formula. This will start with the first ) it encounters. You may need to adjust if you want a different ).

Snag_46d98be.png

georgehenry
5 - Atom

jdminton -  If i need to adjust can you please guide me how to adjust to remove second () as i am new to alteryx still learning these adhoc formulas. 

 

jdminton
12 - Quasar

Based on your example, it should work, but please post back if any issues.

danilang
19 - Altair
19 - Altair

Hi @georgehenry 

 

You can use 

regex_replace([Field1],"^\(.*?\)\s(.*)","$1")

 

Dan

georgehenry
5 - Atom

Thanks i now need to remove first bracket and keep the second one. Thanks

jdminton
12 - Quasar

@georgehenry you didn't provide an example, but you would replace my formula where it is ")" with "]" if that is the type of bracket you are referring to.

 

For the RegEx provided by @danilang , you would use regex_replace([Field1],"^\[.*?\]\s(.*)","$1")

 

OllieClarke
15 - Aurora
15 - Aurora

@georgehenry @danilang's excellent answer assumes that the first parentheses is always at the beginning of the line. If it's possible for the parentheses to occur in other places in the strings then a more complex formula might be needed. (if not then obvs use the above solution).

 

If that is the case try this approach:

image.png

IF CONTAINS([Input],'(') 
AND CONTAINS([Input],')') 
THEN
REGEX_Replace([Input], '(^[^\(\)]*)\(.+?\) ?(.*)','$1$2')
ELSE [Input]
ENDIF


Here I capture all the non parentheses at the beginning of the string, and then capture everything after the first set of parentheses, and concatenate these together (ignoring the space after the parentheses if it's there).

Labels