Alteryx Designer Desktop Discussions

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

Extract N words in a string before and after a certain word

armouche
5 - Atom

Hello.

I have a long text containing several instances of the word "credible". For example: sentence 1. sentence2 that contains the word credible. sentence 3. sentence4 that contains the word credible. sentence5 that contains the word credible. sentence6. sentence7. etc,,,,

 

I want to be able to output a new column that contains 30 words or 100 characters before the word "credible"+ the word credible+ 30 words or 100 characters after the word "credible". In the example above, I will have 3 columns. 

 

I tried RegEx with the expression credible\s+\w+ but getting only the word credible+ 1 word after. The setting is that the output tokenize 20 columns. I am new to RegEx. 

 

Appreciate your help.

2 REPLIES 2
PhilipMannering
16 - Nebula
16 - Nebula

To get part of the way there, you might try replacing credible with "|credible|",

replace([my_field], 'Credible', '|credible|')

And then use a text to columns.

 

Feel free to send an example of the input and output you expect if you're having difficulties thereafter.

armouche
5 - Atom

Thank you. Partially worked with replace. I ended up using (?:\S+\s+){0,30}\bcredible\b(?:\s+\S+){0,30} and that worked much better. Thank you all.

Polls
We’re dying to get your help in determining what the new profile picture frame should be this Halloween. Cast your vote and help us haunt the Community with the best spooky character.
Don’t ghost us—pick your favorite now!
Labels