using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"SMR_.*_(.*)_GRID_(?P<Model>[a-zA-Z]+)_.*";
string input = @"RV_Exp_CX_GRID_08OCT18.dat
RV_Exp_JT_GRID_07NOV18.dat
RV_Exp_OPEL_WB_GRID_21NOV18.dat
RV_Ref_U_GRID_07NOV18.dat
SMR_Exp_CX_GRID_D_11OCT18txt
SMR_Exp_CX_GRID_E_30JUL18txt
SMR_Exp_CX_GRID_JS_07AUG18txt
SMR_Exp_CX_GRID_JT_17SEP18txt
SMR_Exp_GRID_D_07NOV18txt
SMR_Exp_GRID_E_05OCT18txt
SMR_Exp_GRID_JS_08JAN19txt
SMR_Exp_GRID_JT_07NOV18txt
SMR_Ref_GRID_D_07NOV18txt
SMR_Ref_GRID_E_05OCT18txt
SMR_Ref_GRID_JS_08JAN19txt
SMR_Ref_GRID_JT_07NOV18txt
SMR_WB_Exp_GRID_D_14NOV18txt
SMR_WB_Exp_GRID_JS_20FEB19txt
SMR_WB_Exp_GRID_JT_14NOV18txt";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx