I would like to add a certain number of leading zeroes (say up to 3) to all numbers of a string. For example:
Input: /2009/5/song 01 of 12
Outpu
C# version
string input = "/2009/5/song 01 of 12";
string regExPattern = @"(\/\d{4}\/)(\d+)(\/song\s+)(\d+)(\s+of\s+)(\d+)";
string output = Regex.Replace(input, regExPattern, callback =>
{
string yearPrefix = callback.Groups[1].Value;
string digit1 = int.Parse(callback.Groups[2].Value).ToString("0000");
string songText = callback.Groups[3].Value;
string digit2 = int.Parse(callback.Groups[4].Value).ToString("0000");
string ofText = callback.Groups[5].Value;
string digit3 = int.Parse(callback.Groups[6].Value).ToString("0000");
return $"{yearPrefix}{digit1}{songText}{digit2}{ofText}{digit3}";
});