using System.Text.RegularExpressions;
public static void Main()
Console.WriteLine(GetPrecisionFromFormatString("бред"));
private static int GetPrecisionFromFormatString(string customFormat)
if (string.IsNullOrWhiteSpace(customFormat))
var regex = new Regex(@"^{\d+:(N|P|C)(?<precision>\d*)}$");
var precisionString = regex.Match(customFormat).Groups["precision"].Value;
return int.TryParse(precisionString, out precision) ? precision : 2;