re = /^(?:[A-Z] \d|[^\W\d_]{2,}\.?)(?:[- '’][^\W\d_]+\.?)*$/m
str = '########### 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
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html