用法
string str = "date={LastMonths=3}";string bracketsPattern = @"{(?<name>\w+)=(?<value>\w+)}";var bracketsMatch = new Regex(bracketsPattern, RegexOptions.IgnoreCase).Matches(str);foreach (Match item in bracketsMatch){var groupName = item.Groups["name"].Value;var groupValue = item.Groups["value"].Value;switch (groupName){case "LastMonths":str = str.Replace("{" + groupName +"="+ groupValue + "}", string.Format("{0:yyyy-MM-dd}", DateTime.Now.AddMonths(-int.Parse(groupValue))));break;}};
结果:“date=2020-10-23";