using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?>^|\s+|\W)
(
(?>[a-z]\d*|\d+[a-z]?
(?>\(
([a-z]\d*|\d+[a-z]?)
\)[a-z]?
)?)
(?>\.(?>[a-z]|\d+[a-z]?))*
|
(?>M{0,4}(?>CM|CD|D?C{0,3})(?>XC|XL|L?X{0,3})(?>IX|IV|V?I{0,3}))
)
(?>\s+|\W|$)";
string input = @"Appendix 1
6.48
CP 198
3.2.4 G
2
1.
B.
Appendix 1
Annex A
4A.10.1 and 4A.15
4A.21.10
Annex ii
A)
SECTION IV
52.19A
PRACTICE DIRECTION 83—
RSC ORDER 109
Rule 4
ADMINISTRATIVE COURT GUIDANCE
PRACTICE STATEMENT
THE PROTOCOL
C.6
Draft modules
CIS11:
Appendix 13(2)e
2002 no.
(a)
L7.3.1.R
(iii)
";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase | 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