I would like to add a certain number of leading zeroes to a number in a string. For example:
Input: \"page 1\", Output: \"page 001\" Input: \"page 12\", Ouput: \"pa
Use a callback for the replacement, and the String.PadLeft method to pad the digits:
String.PadLeft
string input = "page 1"; input = Regex.Replace(input, @"\d+", m => m.Value.PadLeft(3, '0'));