Alteryx Designer Desktop Discussions

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

Want to pick two words from the sentence

Srawat
8 - Asteroid

Hi,

 

I want to pick starting two words from the sentence if in a sentence have a word then also pick one word . Please advise.

 

I used to picked below regex however not working. single word not picking.

 

Srawat_0-1666347184590.png

 

Thanks,

3 REPLIES 3
JamesCharnley
13 - Pulsar

Hi @Srawat,

 

I'm not a massive RegEx guy but I think this should works. It'll tokenize on the first two words or the whole thing if only one word to one new column. The expression I've used is .*?\s.*?\s|.*

 

JamesCharnley_0-1666347564421.png

 

Emmanuel_G
13 - Pulsar

@Srawat 

 

Find in attachement one way of doing that using Regex.

 

Let me know if this answer is ok for you issue or not.

 

Before

 

Emmanuel_G_0-1666348385037.png

 

After 

 

Emmanuel_G_1-1666348396648.png

 

 

 

DataNath
17 - Castor

Here's an alternative with regular string functions, rather than RegEx. We first perform a check for the number of words and if it's above 1 then we return the first + the second. If the number of words in the string is 1, we just take it as is:

 

DataNath_0-1666348966317.png

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