正则式记录

 1         [TestMethod]
 2         public void UnitTest()
 3         {
 4             var subString = "2017/10/1 0:00:00-2017/10/31 0:00:00";
 5             Regex regexObj = new Regex("(?<year>\d{2,4})/(?<month>\d{1,2})/(?<day>\d{1,2})");
 6             try
 7             {
 8                 string resultString = regexObj.Replace(subString, new
 9                     MatchEvaluator(ComputeReplacement));
10                 Debug.WriteLine(resultString);
11             }
12             catch
13             {
14 
15             }
16         }
17         public string ComputeReplacement(Match matchResult)
18         {
19             Regex innerRegex = new Regex("/");
20             return innerRegex.Replace(matchResult.Value, "-");
21         }

原文地址:https://www.cnblogs.com/ningyouyou/p/8065040.html