Here you can learn about and test regular expressions. You will have to look at anchors, quantifiers and tokens.
A combination of those two. Eg a replace with a regex inside a for loop that looks for the numbers at the end of the string.
you will also have to have a look at the node.send() function to send things from the function node while in the loop: https://nodered.org/docs/user-guide/writing-functions
If you have more questions or need help figuring it out just ask.
stay healthy and have fun, Johannes
This is what I described above utilizing the methods i linked.
We use a for loop to do something eight times
we than use the regex replace to replace numbers at the back of the topic string with nothing hence the "" and use the counter var i of the for loop to add a new number to the string (we have to add 1 as the counter starts at 0)
Its all explained in the links I posted. The [0-9] is part of the regular expression and just means only look for numbers. The only thing you need to change is the i<8 in the for loop.
So I ll explain what the things in the for loop definition do and what the regex does:
i is our counter var we give it a starting value, in this case 0 i=0
we want the loop to run eight times so this is what the second part does: i<8 the loop will run as long as i is smaller than 8.
the third part defines something we do to i on every loop, in this case i++
so it counts up i by one on every loop, so its the same as writing i+=1 or i=i+1
So i will be 0 than 1 than 2 than 3... but it will never reach eight as the loop will break as soon as it is >=8 because the second part wont be true anymore.
is a regular expression which can be used to make rules to find stuff in strings. They are something that is used in allmost all programming languages.
This one has three main parts [0-9] means were only looking for number characters in the string * means dont stop after you find the first number because their might be more $ anchors the search to the back of the string
So the regex will find any number characters at the back of a string. https://regex101.com/r/nA7x1m/2 click on the link and play around with it, its great to understand this and this site is very good at showing you whats going on.
I hope this explains some of it. Those methods are great to have in your toolkit.
Best regards Johannes