Is there a quick way to replace all of some pattern occurrences with data derived from the matched pattern?

For example, if I wanted to replace all occurrences of a number within a string with the same number padded to fixed length with 0s.

In this case if the length is 4, then `ab3cd5` would become `ab0003cd0005`.

My idea was using a StringBuilder and 2 patterns: one would get all numbers and the other would get everything that is not a number, and appending the matches to the builder by the index the matches were found.

I think there might be something simpler.