separating integer value from string
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:
Maybe like this :
Here are variations that works with different strings and can also output that string.
Thanks so much!
The regexp syntax was just really confusing in the beginning :)
could be simplified
![](https://cycling74-web-uploads.s3.amazonaws.com/58ed04e7285705c15ccfa694/2025-01-16T09:15:36Z/image.png)
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.
![](https://cycling74-web-uploads.s3.amazonaws.com/58ed04e7285705c15ccfa694/2025-01-16T09:28:32Z/image.png)
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.'
no, ++ is only misstyped on my side, one + is enough