using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^-----(?:BEGIN|END) (?<label>(?:(?:TRUSTED |X509 )?(?<t1>CERTIFICATE))|(?:(?:NEW )?CERTIFICATE (?<t2>REQUEST))|(?:X509 (?<t3>CRL)))-----$";
string input = @"-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
-----BEGIN TRUSTED CERTIFICATE-----
-----END TRUSTED CERTIFICATE-----
-----BEGIN X509 CERTIFICATE-----
-----END X509 CERTIFICATE-----
-----BEGIN CERTIFICATE REQUEST-----
-----END CERTIFICATE REQUEST-----
-----BEGIN NEW CERTIFICATE REQUEST-----
-----END NEW CERTIFICATE REQUEST-----
-----BEGIN X509 CRL-----
-----END X509 CRL-----";
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