Alteryx Designer Desktop Discussions

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

String extraction to include words around a specific word

Josk
5 - Atom

Hello,

 

I would like extract a part of a sentence around a key word.

 

For example:

 

Input:

1.  John wants to buy 5 apples today in the market.

2.  There are three apples in the fruit bowl.

3.  The red apples fell from the tree.

 

Output: 

1.  buy 5 apples today in

2.  are three apples in the

3.  The red apple fell from

 

Sometimes there could be a number before the term apple or a full word, but ideally I would like to extract 2 either words or numbers (a number with multiple digits should cound as one number) and 2 words after and of course include the word apples.

 

Thanks in advance,

 

Joseph

6 REPLIES 6
Simha
9 - Comet

Hi,

 

Could this solution work?

 

Simha

Simha_0-1583340444693.png

 

MeaganP
6 - Meteoroid

People with more skill can probably make this neater, but this seems to work:

 

 

\<\w+\>\s\<\w+\>\sapples\s\<\w+\>\s\<\w+\> 

 

Josk
5 - Atom

Hi Meagan,

 

I tried what you suggested but got the following error:

 

Josk_0-1583414819158.png

 

Thanks,

 

Joseph

MeaganP
6 - Meteoroid

This is what I have:

There might be a better way, but 'm putting the section we want into a new column then removing the whitespace and selecting only that column

 

 

MeaganP_0-1583446929536.png

 

Josk
5 - Atom

Thanks Simha!  This seems to work.

Simha
9 - Comet

You are welcome @Josk.  I am glad it helped you.

 

Simha

Labels