Alteryx Designer Desktop Discussions

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

Regex solution to extract data from multiple brackets inside a cell

Shahas
8 - Asteroid

Hello,

 

I have a situation where in the data have to be extracted from inside a square bracket []. The column doesn't have any pattern. These are some of the values in the column : 

 

abc [xyz-123] nsk

[ahd-246]

uteh[iwyt-798]

[kudgb-3645] jvsux [oikjh-35945] ahfvd [kdytd-2384]

 

As from the examples above, it doesn't follow any pattern. I just need to extract all the data inside the bracket.

 

I tried using the expression ".*\[(.*)\].*" (excluding ")

 

It works for most cases but if the cell contains more than 1 bracket pair, it only picks up one data.

 

Looking for a solution where in i can extract every data inside any number of square bracket.

 

 

Thanks in advance

5 REPLIES 5
apathetichell
18 - Pollux

try the regex tool in tokenize mode.

BS_THE_ANALYST
14 - Magnetar

@Shahas as @apathetichell mentions, Tokenize can be great here! I've added a couple of extra steps in so you don't have to manually click on how many columns to split by.

BS_THE_ANALYST_0-1676649209341.png

 

RegEx: \[.*?\]

BS_THE_ANALYST_1-1676649334517.png

 

 

 

 

flying008
14 - Magnetar

Hi, @Shahas 

 

Maybe this way as you want:

 

录制_2023_02_18_10_27_48_276.gif

1- Formula: Copy the field [Text] to [Parse].
2- RegEx: Remove all characters not in [ ]  by regular expression.

 

(?<=\[)([\w-]+?)\]

 

3- Text To Columns: Split [Parse] to Columns by "]" .
4- Data Cleansing: Remove all null columns.

 

******

If it can help you , please mark it as a solution and give a like for more share.

Shahas
8 - Asteroid

heyy @flying008

 

The regex which u used provided me with the solution that i was looking for. Thanks

Shahas
8 - Asteroid

Heyy @BS_THE_ANALYST

 

This also works. Thanks for your time

Labels