using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(ABC)_([0-9]{4})_([0-9]+\.[0-9]+\.[0-9]+)(_[a-zA-Z])?(_[a-zA-Z]+)?\.xyz$";
string input = @"ABC_0000_0.0.0.xyz
Group 1 : ABC
Group 2 : 0000
Group 3 : 0.0.0
Group 4 : <empty>
Group 5 : <empty>
ABC_0001_0.1.0_N.xyz
Group 1 : ABC
Group 2 : 0001
Group 3 : 0.1.0
Group 4 : _N
Group 5 : <empty>
ABC_0002_1.1.2_foo.xyz
Group 1 : ABC
Group 2 : 0002
Group 3 : 1.1.2
Group 4 : <empty>
Group 5 : _foo
ABC_0002_42.42.42_N_bar.xyz
Group 1 : ABC
Group 2 : 0002
Group 3 : 42.42.42
Group 4 : _N
Group 5 : _bar";
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