Alteryx Designer Desktop Discussions

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

Regex Tokenize to Split on Delimiter of 2+ more spaces

tasgtm2018
6 - Meteoroid

Hi All,

 

I am using Regex (w/ Tokenize) to split a field out to other columns on a delimiter of 2 or more spaces. So far, I have only been able to do 1 or more using "\S+"

 

What is the best way to do this? Thank you!

9 REPLIES 9
atcodedog05
22 - Nova
22 - Nova

Hi @tasgtm2018 

 

You specify 2 spaces by using \s{2}

 

Hope this helps : )

MarqueeCrew
20 - Arcturus
20 - Arcturus

@tasgtm2018 ,

 

Have you tried:

\s{2,}

that's 2 or more spaces.

 

Cheers,

 

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
IraWatt
17 - Castor
17 - Castor

Hey @tasgtm2018,

As @atcodedog05  says \s{2} is two spaces. For two or more use  \s{2,}. If you want to learn more about Regex the community has some really quick interactive videos on getting to grips with it here Parsing Data. I also recommend regex101: build, test, and debug regex to build regex.

 

Any questions or issues please ask

Ira Watt
Technical Consultant
Watt@Bulien.com 

atcodedog05
22 - Nova
22 - Nova

Hi @tasgtm2018 

 

You can learn more on regex options on this Regex tool mastery page

 

https://community.alteryx.com/t5/Alteryx-Designer-Knowledge-Base/Tool-Mastery-RegEx/ta-p/37689

 

Hope this helps : )

tasgtm2018
6 - Meteoroid

I haven't been able to get it working so far. As an example, the main reason I'm doing this is for cities that have 2 or more words with just one space. I don't want that particular city name (Union City) to be split out, but I want everything else done.

 

Please refer to attached screenshot...thanks!

IraWatt
17 - Castor
17 - Castor

Hey @tasgtm2018,

I will have to admit to have taken this off python - How to match anything except two or more consecutive spaces in a regex? - Stack Overflow. But 

\S+(?:(?!\s{2}).)+

I don't know regex well enough to explain it but the issue is the tokenise needs to match with what you want eg. any text with less then two spaces. The regex above achieves that:

IraWatt_0-1659624003015.png

 

atcodedog05
22 - Nova
22 - Nova

Hi @tasgtm2018 

 

Tokenize method might be tricky for this. Instead, we can look at it in a different way.

 

1. Use REGEX_Replace to replace 2+ spaces with pipe |

2. Use text to column to split on pipe |

 

Give it a try. This method is more understandable, explainable, and modifiable 😅

 

Spoiler
atcodedog05_1-1659624591413.png

 

Hope this helps : )

tasgtm2018
6 - Meteoroid

This works great, thank you!

tasgtm2018
6 - Meteoroid

This is a good solution as well!

Labels