Easiest way to do this is to write a small parser function. This can either handle the end result by itself, or simply return a table with each number in the "string" as an element. This is nice because tables are much easier to work with than strings for this kind of thing.
Now, assuming you're just using an alias that matches an all digit line (such as ^\d+$) then the entire matched line would be stored in matches[1]. So, to get the table:
Now you can iterate through that list and work on it.