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. 12
mainstreet 1
Mainstreet 12a
Main Street 12A
Big New mainstreet 12a
Mainstreet-New 12b
Mains Str. 12z
St. Alexander Street 121 b
Übermorgen Straße 56/58
John Kennedy Street 56/58a
Bahnhofstr. 56-58
Leonhard-Eck-Str. 56 - 58
Älterweg 56-58a
Graf-Anton-Weg 1234
Alexanderstraße 56/58a
Prof.-Ernst-Nathan-Straße 18a - 19b
Prof.-Albert-Einstein-Weg 18a-19b
Prof. Ernst-Nathan-Straße 12
Prof. Albert-Einstein-Weg 15a
######## Not okay ################
Mainstreet
A
B
Z
A 1
B 2
Z 99
Mainstreet #+;:_*´`?=)(/&%$§!
Mainstreet#+;:_*´`?=)(/&%$§!
Mainstreet 2
Mainstreet..
Mainstreet§
Mainstreet 12345
Mainstreet 25-ab
Mainstreet 12ü
Mainstreet 12_
Mainstreet 12!""§$$%&/()
Mainstreet a2
Mainstreet 13àâäèéêë
Mainstreet 0
Mainstreet 123aaa123,
Mainstreet 123 aaa 123
Mainstreet 1a 1
Mainstreet 1a 1'
Mainstreet 1a1
Mainstreet 00 a
Mainstreet 0a
";
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