using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^
(?<batch_number>\d{2})-
(?:
(?<component>QQ|CO|CG)
(?<target_group>[AS])
(?<paper>P)?
)
(?:-
(?<domain>(?:LDW|MAT|REA|SCI|XYZ)
(?<division>[abc])?
)
)?
-(?<authoring_point>[TN])
$";
string input = @"01-COS-SCIa-N
02-COS-SCIb-N
03-COS-SCIc-N
04-QQS-N
05-QQA-N
06-COS-LDW-N
07-COS-XYZ-N
08-CGA-SCI-N
11-COS-MATa-T
12-COS-MATb-T
13-COS-REAa-T
14-COS-REAb-T
15-COS-SCIa-T
16-COS-SCIb-T
17-CGA-SCI-T
18-CGA-MAT-T
19-CGA-REA-T
21-COSP-REAa-T
22-COSP-REAb-T
23-COSP-MATa-T
24-COSP-MATb-T
25-COSP-SCIa-N
26-COSP-SCIa-T
27-QQSP-N
28-QQAP-N
29-COSP-XYZ-N
";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace;
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