How to use the results from OR syntax in substitute part of regexp?

Rivanni's icon

I have symbols like the following ones

"live_set tracks 113 devices 22 chains 7 devices 8"

"live_set tracks 66"

"live_set master_track devices 4"

"live_set tracks 45 devices 22 chains 7 devices 18 chains 0 devices 7 return_chain 2"

So they can vary in length and the pattern is not always 'word number word number etc.'.

I want to add leading zeros so all numbers are 3 or 4 digits long.

I used the OR syntax to find numbers of different lengths, but how do I use these to add the correct number of zeros in the Substitute?

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

Source Audio's icon

it's easy using sprintf

adjust number of leading zeros as wished...

Source Audio's icon
11OLSEN's icon

I don't know if it is possible in one regexp but surely if you divide into single steps