正则表达式替换日期

 

            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;
            });

 

 

posted on 2010-12-13 13:24  shcity  阅读(877)  评论(0编辑  收藏  举报

导航