示例:更改日期格式 static string MDYToDMY(string input) { return Regex.Replace(input,"\\b(?<month>\\d{1,2})/(?<day>\\d{1,2})/(?<year>\\d{2,4})\\b","${day}-${month}-${year}"); } ---------------------------------------------------------------------------------------------------- using System; using System.Globalization; using System.Text.RegularExpressions; public class Class1 { public static void Main() { string dateString = DateTime.Today.ToString("d",DateTimeFormatInfo.InvariantInfo); string resultString = MDYToDMY(dateString); Console.WriteLine("Converted {0} to {1}.",dateString,resultString); } static string MDYToDMY(string input) { return Regex.Replace(input,"${day}-${month}-${year}"); } }