using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(?:[A-Z] \d|[^\W\d_]{2,}\.?)(?:[- '’][^\W\d_]+\.?)*$";
string input = @"########### Absolutly Fine ################
Mainstreet.
Mainstreet
Main Street
Big New mainstreet
Mainstreet-New
Mains Str.
St. Alexander Street
Übermorgen Straße
John Kennedy Street
Bahnhofstr.
Leonhard-Eck-Str.
Älterweg
Graf-Anton-Weg
Alexanderstraße
Prof.-Ernst-Nathan-Straße
Prof.-Albert-Einstein-Weg
Prof. Ernst-Nathan-Straße
Prof. Albert-Einstein-Weg
########## Not very common but fine!!! ###################
A 1
K 7
H 2
P 1
I 7
E 7
T 3
######## Not okay ################
A
B
Mainstreet #+;:_*´`?=)(/&%$§!
Mainstreet#+;:_*´`?=)(/&%$§!
Mainstreet 2
Mainstreet..
Mainstreet§
";
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