In Datamapper I try to create a regex to split address parts (only Mid-European adresses) into
- street
- (countrycode) ZIP City
- country
but failed
Examples of the possible formats (captured lines already seperated by |)
Sir|Alfred Testman |c/o Watermelon 2245 Inc|Brownstreet 13|6280 Hochdorf|SCHWEIZ
Alfred Testman |Testman 2245|Yellowlane 13|CH-6280 Hochdorf|SCHWEIZ
Boris Checkman |c/o Bavarian 5555|Morninglane 13|CH-6280 Hochdorf
Peter Pan|Oststrasse 13|99999 Simcity
goal is to identify the first 4-5 digit ZIP code (with the approrpiate countrycode)
record.fields.AdrBlock.match(/(\d{4,5}\s)(.[^|]+)/gi).slice(-1)[0].trim(); //works but is stripping the country code. Prerequisite:
Country may be empty, ZIP may be preceeded by countrycode, ZIP is 4-5 digits, street is always the line before the ZIP/city.
So result should look like
Line 1
Street: Brownstreet 13
Zipcity: 6280 Hochdorf
country: SCHWEIZ
Line 2:
Street: Yellowlane 13
ZipCity: CH-6280 Hochdorf
country: SCHWEIZ
Line 3:
Street: Morninglane 13
Zipcity: CH-6280 Hochdorf
country: null
Line4:
Street:Oststrasse 13
Ziptcity: 99999 Simcity
country: null
I tried hundreds of regex combination but none worked for every of these cases.
appreciate any help,
Ralf.