using System.Collections.Generic;
using System.Text.RegularExpressions;
public static void Main()
string input = "Age should be between 1 and 99.";
string required = "The {0} field is required.";
string date = "The {0} field is not a valid date.";
string range = "{0} should be between {1} and {2}.";
var possibilities = new []
new KeyValuePair<string,Action>(ToRegex(required), ()=>((Action)(() => { isRequired = true;}))()),
new KeyValuePair<string,Action>(ToRegex(date), ()=>((Action)(() => { isDate = true;}))()),
new KeyValuePair<string,Action>(ToRegex(range), ()=>((Action)(() => { isRange = true;}))())
var result = possibilities
.Where(x=>Regex.Match(input,x.Key).Success)
.Select(x=> new KeyValuePair<IEnumerable<string>,Action>(
Regex.Match(input,x.Key).Groups.Cast<Group>().Where(c=>c.Name.StartsWith("Field")).Select(c=>c.Value),
Console.WriteLine($"{nameof(extractedField)}={string.Join(",",fields)},{Environment.NewLine}{nameof(isRequired)}={isRequired},{Environment.NewLine}{nameof(isDate)}={isDate}");
public static string ToRegex(string value)
var result = new List<string>();
foreach(var item in value.Split(' '))
if(Regex.Match(item,@"{(?<Value>\d*)}").Success)
var match = Regex.Match(item,@"{(?<Value>\d*)}");
result.Add(Regex.Replace(item,@"{(?<Value>\d*)}",$"(?<Field{match.Groups["Value"].Value}>\\S*)"));
return string.Join(" ",result);