Replace part of string by same lenght part of another

2020-03-26 c# regex

I'd like to make regex function which will replace by mask where
A means number of day taken from right
B means number of month taken from right
C means number of year taken from right
date = (DD/MM/YYYY) 20.02.2020

so from mask AA-B-CC could be something like 20-2-20

Mask and date will be parameters of function

public static string CreateMask(string mask, DateTimeOffset date)
{
   string output = Regex.Replace(mask, @"[A]", date.Day.ToString()); // but only replace as much chars as mask contains and taken from right ( AA from 2020 is 20)
   // month ..
   // year ...
   return output;
}

Any suggestions? Thank you

Answers

Related