using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\bHRB\b(?:[-\s]N(?:umme)?r)?[,.:\s]*(\d+)";
string input = @"######## Most cases are likes this: ###############
HRB 21156
HRB, 1234
HRB: 99887
######## Some cases can be likes this: ###############
######## How to I catch the numbers as shown above? ##########
HRB-Nummer 21156
HRB-Nr. 12345
HRB-Nr: 21156
HRB Nr. 21156
HRB Nr: 21156
HRB Nr.: 21156
HRB Nummer 21156
";
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