separating integer value from string

Friendly Coder's icon

Hey fellows!

I've been fighting with a seemingly easy problem for the last hours and finally found kind of a workaround, but i wanted to know if there is an easier way to do this because i can't imagine there's no other way.

So basically I'm receiving a message that looks like "generator[0]" from a js, and only the number within the brackets changes. To use the integer i want to separate it from the rest, but all the normal list and pack operators didn't seem to work because it is not divided by any spacebars. Is there an easy way to extract the integer value out of this message or split it up to get only the number in brackets?

Here is my rather complicated workaround:

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

pdelges's icon

Maybe like this :

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

TFL's icon

Here are variations that works with different strings and can also output that string.

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

Friendly Coder's icon

Thanks so much!

The regexp syntax was just really confusing in the beginning :)

Source Audio's icon

could be simplified

only numeric \\d++ or alphanumeric \\w++

but if you have floats instead of integers,

none of above examples would work.

you would have to replace all brackets and other "unwanted" chars

with spaces and then route items by type.

TFL's icon

Is there a reason for two '+' in \\d++ and \\w++? For me the same but with one '+' would give the same.

But both \\d+ and \\d++ forms will catch any number in the string part: track_4[12] will give 4 12 which might not be very practical to work with.

I never had to deal with floats in regexp, and it makes me realize just now how complicated it can be! Especially if you also want to match forms like '.1' or '0.'

Source Audio's icon

no, ++ is only misstyped on my side, one + is enough