regexp split any number with spaces

pismo's icon

Hi
I'm scratching my head around a regexp problem and I can't find any solution to a problem that seems simple.
I want to split any number with spaces.
123 > 1 2 3
54682 > 5 4 6 8 2
I've tried several things but without success.
Thanks for your help !

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

You could simply use "[0-9] " as your expression and use the substring outlet:

pismo's icon

Thanks Jan ! Now I feel really stupid. I started with too complicated things...

Jan M's icon

well, it a Max specific "hack", because it offers the substring outlet. in plain regex it would be a little bit more work ;)

metamax's icon

.{1} is a good choice if you have an unknown mix of numbers, letters and symbols as input.

Max Patch
Copy patch and select New From Clipboard in Max.

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

Hi Metamax,
Your code seems to work only when there's at least a letter or a symbol inside. If it's only numbers, I need to bang it twice and the output put the last number first.
793 > 3 7 0 3
Is it the same for you ?

metamax's icon

Hi Pismo, yes, my mistake. Just add [tosymbol] prior to the input.

Max Patch
Copy patch and select New From Clipboard in Max.

pismo's icon

Nice ! Thanks ! Now I understand better how regexp works. I've found the same code as yours before but I was struggling to make it work.

Jan M's icon

That's what I think each time I write a regex and when writing the next one I feel like starting all over. Sometimes I wonder what kind of person it was who came up with it :)

PS: The most impressive one I once came across was a rexex to determine prime numbers!!!

pismo's icon

Haha it's like black magic to me :) The problem is that I don't use it much. So every time I need it I also have to start from scratch because I only know a specific trick (and most of the time I've forget it). But when it finally works I like the magic effect :)