splitting a varying size list at a specific character

youcloudsofdoom's icon

I have a list such as (this that 13 23 another // more again the same), and I want to split that list at the "//", so that I can route what comes before and after the // to different places. This list is constantly being populate and the number of items on either side of // is not a fixed amount. Can anyone suggest how I could achieve this?

pdelges's icon

regexp could be a solution. This one is not very elegant but it should help you (sorry for the screenshot, I use Max' demo right now - without copy features :-)

Screen-Shot-2015-07-21-at-17.17.12.png
png
youcloudsofdoom's icon

Ah, I've been playing with regexp, that's a very good solution! Just to throw a spanner in it though, how would it work if you didn't know how many separate sections you wanted to separate? I've just been playing around with it and it looks like regexp will only pass the backreferences if the input has the amount stipulated in the arguments.

pdelges's icon

So without regexp (and without licence, I'm home and my Max licences are at work), maybe even more elegant:

Screen-Shot-2015-07-21-at-18.51.16.png
png
youcloudsofdoom's icon

Oh, that is very elegant, thanks! How would you suggest I split them at the other end? I basically need to send each group to a different inlet elsewhere.

pdelges's icon
Max Patch
Copy patch and select New From Clipboard in Max.

As you don't know how many groups you have, you can't send them to different outlets.
You could tag each sub-list with its position in the main list. Then you could use this tag thru a route or with forward :

youcloudsofdoom's icon

That's really interesting, I haven't seen the [forward] object before too, super useful. Huge thanks Patrick!

youcloudsofdoom's icon

Here's something related to this that I'm stumped on, wonder if you have any ideas - what if in your last patch the 4 5 6 dropped out of the initial list, but I wanted to keep the other numbers going to the same outputs? And then 10 11 12 get added to the initial list, but are outputted to the first empty slot on the route (what was previously taken by 4 5 6). Any ideas how I could achieve this?