Link to home
Start Free TrialLog in
Avatar of peispud
peispudFlag for Canada

asked on

Extract city name from address field - Regex

Hi. 

My code needs to go through all the records in a database and  try to glean the city as accurately as possible from an address field. This data is a bit sloppy,  


Examples are shown below.,    

In each case, I would like to extract "New York"

I would appreciate a regex  criteria string.


"123 New York,"
"123 New York City, "
 "  New York ,"

" New York / the big apple"

"New York (The big apple)".

"New York"

Thank you.

Avatar of Dr. Klahn
Dr. Klahn

I think you will find it much easier -- and probably far more accurate -- to take a different approach.

Using the post code, look the city up in the public database maintained by the country's postal service.  These databases are available both online and for free download.  The result will be a city name formatted as it is desired by the postal service and will also handle such unusual cases as military and diplomatic post codes.
Avatar of peispud

ASKER

This particular database does not have a postal code.  The database is old. The address info is not meant to provide mailing address.  Just a location for equipment.  A location to drive to.
Do you  have a list of city names you want to find/extract?
Avatar of peispud

ASKER

I do not have a list of city names.
This is my effort to improve the data.  My code would write a "predictive" value in a new [City] field which would be evaluated / corrected by a person later on.
ASKER CERTIFIED SOLUTION
Avatar of louisfr
louisfr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial