Regex for city and street name

PParker

Hi, I am looking for 2 regex which describe:

1) a valid name of a street

2) a valid name of a city

Valid street names are:

  • Mainstreet.
  • Mainstreet
  • Main Street
  • Big New mainstreet
  • Mainstreet-New
  • Mains Str.
  • St. Alexander Street
  • abcÜüßäÄöÖàâäèéêëîï ôœùûüÿçÀÂ-ÄÈÉÊËÎÏÔŒÙÛÜŸÇ.
  • John Kennedy Street

Not valid street names are:

  • Mainstreet #+;:_*´`?=)(/&%$§!
  • Mainstreet#+;:_*´`?=)(/&%$§!
  • Mainstreet 2
  • Mainstreet..
  • Mainstreet§

Valid cities are:

  • Edinôœùûüÿ
  • Berlin.
  • St. Petersburg
  • New-Berlin
  • Aue-Bad Schlema
  • Frankfurt am Main
  • Nürnberg
  • Ab
  • New York CityßäÄöÖàâäèéêëîïôœùûüÿçÀÂ-ÄÈÉÊËÎÏÔŒÙÛÜŸ

Not valid cities are:

  • Edingburgh 123
  • Edingburg123
  • St. Andrews 12
  • Berlin,#+;:_*´`?=)(/&%$§!
  • Berlin__

The solutions that I have at the moment matches very close but not perfectly:

For city and street name:

^[^\W\d_]+(?:[-\s][^\W\d_]+)*[.]?$

Unfortunately no match for these examples (the rest works fine):

  • St. Alexander Street
  • St. Petersburg

If you have more simple solutions, I am happy to learn sth. new! :-)

Wiktor Stribiżew

To make it match St. Alexander Street and St. Petersburg, you just need to add an optional dot after the letter matching patterns:

^[^\W\d_]+\.?(?:[-\s][^\W\d_]+\.?)*$
#         ^^^                 ^^^

See the regex demo.

Also, it might make sense to add a single apostrophe to the regex:

^[^\W\d_]+\.?(?:[-\s'’][^\W\d_]+\.?)*$

See the regex demo.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Regex: Omitting street address up until the city?

OSM - Extract Street Name, Lat/Long, and City

RegEx for street name especially in germany

R: Get zipcode from just Street Name, City, and State

Python regex to match street name and house number

regex doesn't get street name

Regex for putting comma before city name in address

Grab City Name from an Address via Regex

Cross referencing street and city names

Best regex to fetch street name from a partial address

Ad one more pattern to my street-name regex (Python)

Add one more pattern to my street-name regex

Extract House Number and Street Name from string using Python Regex

Regex for getting just name of street and number from messy address

how to show the street name, postcode/zip-code, city automatically of the current location using maps api v2

Regex for words in street addresses

Split street address into street number and street name in r

Edit regex to recognise very short street name or number for Python 2.7 script and avoid fatal attribute error

Convert coordinates to City name?

spell out the direction of a street name

Will SOLR perform matching on the street name?

Is possible to get street name in route

Getting street,city and country by reverse geocoding using google

extracting city and state information from a google street address

How to extract street, city, etc. from GMSPlace Address Components

How to get Current Location(Street,City, etc,..) using gps in Android

Splitting address with various delimiters into street address, city, state, zip and country

How to find all street intersections in my city using Postgis

Python .replace 'st' with 'street' but leave street name the same