Regex Tokenize to Split on Delimiter of 2+ more spaces
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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!
Solved! Go to Solution.
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Have you tried:
\s{2,}
that's 2 or more spaces.
Cheers,
Mark
Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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 : )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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 😅
Hope this helps : )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
This works great, thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
This is a good solution as well!
