Question: I want to pad left every number with zeroes (it has to be 8 digits) in my string.

e.g.

```
asd 123 rete > asd 00000123 rete
4444 my text > 00004444 my text

```

Is it possible to do this using regular expressions? Especially `Regex.Replace()`?

Notice that the number of zeroes is different for different numbers. I mean the padded number has to be 8 digits long.

Answer: 
Microsoft has built in functions for this:

```
someString = someString.PadLeft(8, '0');

```

And here's an article on [MSDN](http://msdn.microsoft.com/en-us/library/dd260048.aspx)

To use a regular expression, do something like this:

```
string someText = "asd 123 rete"; 
someText = Regex.Replace(someText, @"\d+", n => n.Value.PadLeft(8, '0'));

```
If you don't have any attachment to Regex just use format strings:

[C# convert int to string with padding zeros?](https://stackoverflow.com/questions/4325267/c-sharp-convert-int-to-string-with-padding-zeros)

<http://www.xtremedotnettalk.com/showthread.php?t=101461>