正则表达式替换日期
string str = @"test_{@ReportDate:yyyyMMdd}\{@ReportDate:yyyy}\{@ReportDate:MM}\{@ReportDate:dd}\ss.xls";
Regex regex = new Regex(@"\{@ReportDate:(?<p>[a-zA-Z]*)\}");
DateTime time = DateTime.Now;
string r = regex.Replace(str, match =>
{
var p = match.Groups["p"].Value;
var t = time.ToString(p);
return t;
});
Regex regex = new Regex(@"\{@ReportDate:(?<p>[a-zA-Z]*)\}");
DateTime time = DateTime.Now;
string r = regex.Replace(str, match =>
{
var p = match.Groups["p"].Value;
var t = time.ToString(p);
return t;
});