Alteryx Designer Desktop Discussions

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

Extract two words before and two words after the targeted word from string

SagarGite
7 - Meteor

Hello team,

 

I would like to have workflow for extracting two words before and two words after the targeted word from string.

 

String is in Column "Indication" and targeted word for the string is in column "Indication word". Expected output is in "Additional word info" column

 

Please see attached file for sample data and expected output.

 

Thanks in advance

4 REPLIES 4
PhilipMannering
16 - Nebula
16 - Nebula

Something like this kind of works,

PhilipMannering_0-1640087858634.png

 

PhilipMannering
16 - Nebula
16 - Nebula

You can also do it in one expression using the Formula Tool using,

 

trim(regex_replace('_ _ ' + [Indication] + ' _ _', '.*(\b\w+\b \b\w+\b ' + [Indication Word] + ' \b\w+\b \b\w+\b).*', '$1'), '_ ')

 

mceleavey
17 - Castor
17 - Castor

Hi @SagarGite ,

 

I used the method of splitting the data to rows on the space:

 

mceleavey_0-1640088472122.png

 

Then using a simple multi-row formula to say if the Indication word equals the Indication field, then take two above and below:

mceleavey_1-1640088521680.png

 

Then pivot it back with a cross-tab:

 

mceleavey_2-1640088549078.png

 

I hope this helps,

 

M.

 



Bulien

PhilipMannering
16 - Nebula
16 - Nebula

Or you can do it with a single regex expression,

 

regex_replace([Indication], '.*?((\b\w+\b (\b\w+\b )?)?' + [Indication Word] + '( \b\w+\b( \b\w+\b)?)?).*', '$1')
Labels