Extract Max Length of allowed string from Regex object
问题 Is it possible to extract a max length of an allowed string from a regex pattern once it has been loaded into a C# Regex object? If I have a Regex string defined as @"^[A-Z0-9]{0,20}$" , I could use string manipulation to get the maximum allowed length of 20 . However is there a way I can get that more easily, for instance via a Regex object as follows: var r = new Regex(@"^[A-Z0-9]{0,20}$"); // var max = r.MaxLength; Update To set some context, I have an Asp.Net MVC 5 application in which we