Split by multiple separators

I've written this special splitter so you can easily split a text value by multiple delimiters but what result should it give with a input of "one, two.three four " and seperators of , space .

with gaps

or this (my preferred option)

without gaps

That's good, but it already exists: Split by Delimiters

Mine wasn't good - it was a bodge solution

I'll use the other one and nice to know it behaves in my preffered manner :slight_smile:


Just for "fun" - I've created a JavaScript based version that uses RegEx expressions to determine how the text is split :slight_smile:

untitled script pic - 2024-03-02T163237.271

I’m afraid @bombmanyeeted’s split-by-delimiters is (IMAO) flawed though, as demonstrated by changing the order of delimiters:

Here’s for an alternative approach:

Please excuse me for misspelling “delimiters”.

Well spotted
Thanks for an improved version :slight_smile:

But what should this report? I'd say it should report a list with 1 empty item.

IMO the empty list is fine.

here's my version

untitled script pic

i used recursion to split up the text

Your version is much faster
untitled script pic

untitled script pic (1)

The difference is spectacular!
The trick that @joecooldoo employs is using untitled script pic-8 as a hyperblock - very smart, hadn't thought of that before.

It does have one issue, though:


The latter script is considerably slower than @joecooldoo's, though still much faster than my previous proposal. This is caused by the filter, I guess. Perhaps @joecooldoo can speed it up again :slight_smile:

Update: one way to speed it up is moving the code from within inner loop to a self-contained block - I wonder why that is.

I'd modified joecooldoo's to use a helper block but I like your method of using a variable to save the hassle of having a helper :slight_smile:

untitled script pic - 2024-03-04T134150.446

This has been a good little exercise :slight_smile:

My latest version is (corrected version 4Mar2023 21:29UTC]
splitBy script pic (1)

which assumes that if your only supply one parameter, then you want to treat it as a RegEx value

Philosophy is that if you just wanted a split by one value and not use RegEx then you'd use the standard split by reporter

thats not a bug. :slight_smile:

primitive snap SPLIT BY block:
untitled script pic (1)

in fact thats what the other programming languages I tested did as well






Wow. That certainly proves your point. (Also, nice VS Code theme.)

I agree, my mistake!

I'm getting deeper down the rabbit hole... :slight_smile:

The drive behind a multiple delimiter split for me, is to easily parse Advent of Code type problems such as this one

splitBy script pic (2)

So my latest version will map the split(s) over the input if the input is a list

And you can pre-split the input text into a list to deal with data like the above